$dept = $_POST['dept'];
$sql2 = "SELECT batch FROM $dept";
$result2 = mysql_query($sql2);
echo '<form method="post" id="try2" action="pillar.php">';
echo 'Select Batch: ';
echo '<select name="batch" id="batch">';
while($q = mysql_fetch_assoc($result2))
{
$batch = $q['batch'];
echo '<option>'.$batch.'</option>';
}
echo '</select><br><br>';
echo '<input type="submit">';
。如何限制使用select语句从数据库中检索的相同值输出数据?请帮忙!提前谢谢!
答案 0 :(得分:0)
$sql2 = "SELECT batch FROM $dept GROUP BY `batch`";
GROUP BY
子句会导致所有行按batch
列进行分组,只会为每个batch
值返回一行。
答案 1 :(得分:0)
为什么不对SQL查询进行分组?
"SELECT `batch` FROM $dept GROUP BY `batch`";