I have a table bus with columns bus_id, bus_no.
I tried echo multiple with multi selection, I tried the below code but its repeating the bus_no.
Please help me to echo all buses and echo selected beside the selected ones.
<form name="editstudent" method="get" action="testmulti.php">
<select name="numBus[]" multiple>
<?php
$selBus=mysql_query("SELECT * FROM najdsy_bus order by bus_id");
while ($rowBus=mysql_fetch_array($selBus)) {
foreach ($numBus as $key=> $value) {
if ($rowBus['bus_id']==$value) {
$SelectedBus = "selected";
} else {
$SelectedBus = "";
}
echo '<option value="'.$rowBus['bus_id'].'"'.$SelectedBus.'>'.$rowBus['bus_no'].' '.$SelectedBus.'</option>';
}
}
?>
</select>
<br/>
<input type="submit" value="test">
</form>
mysql_*functions. They are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. If you care to learn, here is a quite good PDO-related tutorial.