Greaser9780 Posted February 27, 2007 Share Posted February 27, 2007 The following is some of my code for a dropdown box from a query. I tried ORDERing the info many ways. There are 12 names in the table but it always shows 11. What am I missing? <select name='1name'> <?php $sql1=mysql_query("SELECT * FROM draft_teams WHERE teamid > '0' ORDER BY name DESC") or die(mysql_error()); $res1=mysql_fetch_array($sql1); $rst1=$res1['name']; while ($res1 = mysql_fetch_array($sql1, MYSQL_ASSOC)){ echo "<option value='" . $res1['name'] . "'>" . $res1['name'] . "</option>"; } ?> </select><br> Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/ Share on other sites More sharing options...
Yesideez Posted February 27, 2007 Share Posted February 27, 2007 Try this: <select name='1name'> <?php $sql1=mysql_query("SELECT * FROM draft_teams WHERE teamid > '0' ORDER BY name DESC") or die(mysql_error()); while ($res1 = mysql_fetch_array($sql1, MYSQL_ASSOC)){ echo "<option value='" . $res1['name'] . "'>" . $res1['name'] . "</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/#findComment-195169 Share on other sites More sharing options...
Orio Posted February 27, 2007 Share Posted February 27, 2007 You called mysql_fetch_array once before the loop, so one is "missing". Try this: <select name='1name'> <?php $result1 = mysql_query("SELECT * FROM `draft_teams` WHERE teamid > 0 ORDER BY name DESC") or die(mysql_error()); while ($row = mysql_fetch_assoc($result1)) echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>"; ?> </select> Orio. Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/#findComment-195170 Share on other sites More sharing options...
Greaser9780 Posted February 27, 2007 Author Share Posted February 27, 2007 I think I get it. Because I called it outside the while loop already that's why it left one out. Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/#findComment-195177 Share on other sites More sharing options...
Yesideez Posted February 27, 2007 Share Posted February 27, 2007 You got it! Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/#findComment-195179 Share on other sites More sharing options...
Orio Posted February 27, 2007 Share Posted February 27, 2007 I think I get it. Because I called it outside the while loop already that's why it left one out. Exactly When one result "missing", in most cases it means you called mysql_fetch_array() before the loop. lol Yesideez, I can't handle your speed! Orio. Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/#findComment-195180 Share on other sites More sharing options...
Yesideez Posted February 27, 2007 Share Posted February 27, 2007 lol Yesideez, I can't handle your speed! Orio. Yeah but you're explaining it in a bit more detail than I am if that's any consolation Link to comment https://forums.phpfreaks.com/topic/40337-solved-dropdown-from-query-always-lists-1-missing/#findComment-195184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.