hi
i have got a simple table in my database like this:
from|to
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>
<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..

Member Avatar for diafol

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:

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

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

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