Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only 1 of 2 dropdowns filled 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
Can someone see why only List1 gets filled, and List2 stays empty? It does get a select name of yyyy. I found if I remmed out lines for List1, then List2 filled? Thanks

</select></td>
<td align="left" width="421" valign="top">

<?
echo "<select name=\"List1\">";
echo "<option size =10 selected>xxxx</option>";
if(mysql_num_rows($result))
{
while($row = mysql_fetch_assoc($result))
{
echo "<option>$row[Orderdate]</option>";
}
}
else {
echo "<option>No Data Present</option>";
}

echo '</select name>';
?>

</select></td>
<td align="left" width="400" valign="top">

<?
echo "<select name=\"List2\">";
echo "<option size =10 selected>yyyy</option>";
if(mysql_num_rows($result))
{
while($row = mysql_fetch_assoc($result))
{
echo "<option>$row[Orderdate]</option>";
}
}
else {
echo "<option>No Data Present</option>";
}

echo '</select name>';
?>

</select></td></tr>
</table>
</div>
<p>&nbsp;</p>
 
you've already moved to the end of the result set, so the next time you get to the loop, it never executes.

try this in between loops:

Code:
mysql_data_seek($result, 0);

if that doesn't work, consider storing the result in an associative array, then looping through that.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
It's because the section:

[tt] while($row = mysql_fetch_assoc($result))
{
echo "<option>$row[Orderdate]</option>";
}
[/tt]

that populates the first SELECT loops through and consumes all the output of your query. When your script gets to the next loop to populate the second SELECT, there are no more rows to fetch, so the loop doesn't run.






Want the best answers? Ask the best questions! TANSTAAFL!
 
Thankyou both, that makes sense, end of recordset/rows. Thanks cLFlaVA, your bit of code brought it back to life!
A star deserved for that headache to go.
 
FYI, in general if you have to loop over the same data twice you're probably not taking the most efficient route.

In this case it's an issue of space vs. speed, you're choosing a smaller and slower solution... I'm guessing you'd prefer a larger and faster one.

Namely, loop once, put the output into a buffer variable first, then output it later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top