我在下面有这个工作代码,但是我想将它从下拉列表更改为复选框,因此可以选择并传递多个选项以进行进一步操作,而不仅仅是下拉列表允许的操作。 我是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>';
答案 0 :(得分: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>';
?>
将multiple
附加到select
,如下所示@sudhakar说
echo '<select name="pal_numb" multiple><option>Select Pal</option>'.$pals.'</select>';
答案 1 :(得分: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>';
使用此代码