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> Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 27, 2007 Share Posted February 27, 2007 You got it! Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.