开发者

restrict output of same values on dropdown

$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 '<opti开发者_JS百科on>'.$batch.'</option>'; 
}
echo '</select><br><br>';
echo '<input type="submit">';

.how can i restrict the outputting of data with the same value that was retrieved from the database using the select statement? help pls! Thanks in advance!


Why not grouping your SQL-query?

"SELECT `batch` FROM $dept GROUP BY `batch`";


$sql2 = "SELECT batch FROM $dept GROUP BY `batch`";

The GROUP BY clause will cause all the rows to be grouped by the batch column effectively only returning one row for each batch value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜