0

我在下面有这个工作代码,但我想将它从下拉列表更改为复选框,因此可以选择并传递多个选项以进行进一步操作,而不仅仅是下拉列表允许的一个选项。我对 PHP 很陌生,并且对此进行了大量搜索,但没有任何成功。任何帮助深表感谢。

    $l = $_POST['LT'];
    $pals = '';

    $r = mysql_query("SELECT DISTINCT pal_num FROM pl_tab WHERE lt_num='$l'");

    while($row = mysql_fetch_assoc($r))
    {
        $pals .= '<option>'.$row['pal_num'].'</option>';

    }

    if($pal == '')
        echo '';
    else 
    echo '<form name="get_pal" action="post.php" method="POST">';
    echo '<select name="pal_numb"><option>Select Pal</option>'.$pals.'</select>';
    echo '<input type="submit" name="post" value="Go!">';
    echo '</form>';
4

2 回答 2

2

带复选框

<?php
    $l = $_POST['LT'];
    $pals = '';

    $r = mysql_query("SELECT DISTINCT pal_num FROM pl_tab WHERE lt_num='$l'");

    while($row = mysql_fetch_assoc($r))
    {
        $pals .= '<input type="checkbox" name="pal_numb[]" value="'.$row['pal_num'].'">'.$row['pal_num'].'<br>';
    }

    if($pal == '')
        echo '';
    else
    echo '<form name="get_pal" action="post.php" method="POST">';
    echo $pals;
    echo '<input type="submit" name="post" value="Go!">';
    echo '</form>';
?>

多选

正如@sudhakar 所说,在下面multiple添加喜欢select

 echo '<select name="pal_numb" multiple><option>Select Pal</option>'.$pals.'</select>';
于 2013-08-26T06:30:41.323 回答
1
$l = $_POST['LT'];
$pals = '';

$r = mysql_query("SELECT DISTINCT pal_num FROM pl_tab WHERE lt_num='$l'");

while($row = mysql_fetch_assoc($r))
{
   $pals .= '<br /><input type="checkbox" name="pal_numb" value="'.$row['pal_num'].'">'.$row['pal_num'];

}

if($pal == '')
    echo '';
else 
echo '<form name="get_pal" action="post.php" method="POST">';
echo $pals;
echo '<input type="submit" name="post" value="Go!">';
echo '</form>';

使用此代码

于 2013-08-26T06:31:37.590 回答