0

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..

2
Contributors
1
Reply
8
Views
7 Years
Discussion Span
Last Post by diafol
0

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>
This question has already been answered. 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.