i have got a simple table in my database like this:
bangalore | delhi
chennai | mumbai

i am using two drop down list to display this data. here is my code:

<select  name="From">
              <?php while($row = mysql_fetch_row($result))
               { ?>
              <option value="<?php echo $row[0];?>"><?php echo $row[0];?></option>
              <?php }?>
<select style="width: 150px;" name="To">
              <?php while($row = mysql_fetch_row($result))
               { ?>
              <option value="<?php echo $row[1];?>"><?php echo $row[1];?></option>
              <?php }?>

the first drop down list is working fine but the second isn't working.
thanks in advance..

Re: getting values from database into drop down list 80 80
Member Avatar

If you're using the while loop on the same recordset object, then no it won't work. The recordset pointer has reached the end of the set after the first loop.

I suggest placing the 'interior' or the select fields into 2 php variables and then just echoing this out inside each select:

$from = "";
$to = "";
  $from .= "<option value=\"{$row[0]}\">{$row[0]}</option>";
  $to .= "<option value=\"{$row[1]}\">{$row[1]}</option>";

<select name="From">
<?php echo $from;?>
<select style="width: 150px;" name="To">
<?php echo $to;?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.