0

Hi, For a dropdown , I display from one table, While Editing How to show the selected value in that dropdown.

<select name="dropdown">
<option value="">--Select--</option>
<?php
$a=mysql_query("Select * from student whre status='0'")or die(mysql_error());
$b=mysql_num_rows($a);
if($b >0)
{
while($row=mysql_fetch_array($a))
{
?>
<option value="<?php echo $row['st_id']?>"><?php echo $row['name'] ?></option>
<?php } } ?>
</select>

This is my dynamic select box code for insert , I don`t know how to edit? Can any one tell me?
3
Contributors
2
Replies
18
Views
2 Years
Discussion Span
Last Post by Gideon_1
0
<select name="dropdown">
<option value="">--Select--</option>
<?php
$a=mysql_query("Select * from student whre status='0'")or die(mysql_error());
$b=mysql_num_rows($a);
if($b >0)
{
while($row=mysql_fetch_array($a))
{
$selected = ( $row['st_id']=="id_for_compare" ? ' selected' : '' );
echo '
<option value="'.$row['st_id'].'"'.$selected.'>'.$row['name'].'</option>';
} } ?>
</select>

or use $row['name'] if you want compare rowname

0

Please first of all mysql database connection layer is deprecated, so try to use mysqli or PDO for database connections.

And, I don't actually get what you are trying to say. Can you please ellaborate your question further.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.