Eiolon Posted April 19, 2008 Share Posted April 19, 2008 It gives me a list of the users except the first record in the table. I tried querying a different table and get the same result. Thanks for your help! $query_users = "SELECT id, username FROM users"; $users = mysql_query($query_users) OR die ('Cannot retrieve a list of users.'); $row_users = mysql_fetch_array($users); <select name="user"> <?php while($row_users = mysql_fetch_array($users)) { print '<option value="' . $row_users['id'] . '">' . $row_users['username'] . '</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/ Share on other sites More sharing options...
unidox Posted April 19, 2008 Share Posted April 19, 2008 Try changing this: $query_users = "SELECT id, username FROM users"; to $query_users = "SELECT * FROM users"; Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/#findComment-521417 Share on other sites More sharing options...
Eiolon Posted April 19, 2008 Author Share Posted April 19, 2008 Same result Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/#findComment-521431 Share on other sites More sharing options...
unidox Posted April 19, 2008 Share Posted April 19, 2008 Try this: <?php $q = mysql_query("SELECT * FROM `users`") or die(mysql_error()); ?> <select name="user"> <? while ($r = mysql_fetch_array($q)) { echo "<option value=\"" . $r['id'] . "\">" . $r['username'] . "</option>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/#findComment-521466 Share on other sites More sharing options...
Eiolon Posted April 19, 2008 Author Share Posted April 19, 2008 Nothing is shown in the drop down menu when I use that code, probably because there is no result or row in your SQL statement. Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/#findComment-521511 Share on other sites More sharing options...
laffin Posted April 19, 2008 Share Posted April 19, 2008 Its cuz u use mysql_fetch_array in and before the loop. remove it from before the loop. otherwise the first record is always lost $query_users = "SELECT id, username FROM users"; $users = mysql_query($query_users) OR die ('Cannot retrieve a list of users.'); //$row_users = mysql_fetch_array($users); <select name="user"> <?php while($row_users = mysql_fetch_array($users)) { print '<option value="' . $row_users['id'] . '">' . $row_users['username'] . '</option>'; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/#findComment-521514 Share on other sites More sharing options...
Eiolon Posted April 19, 2008 Author Share Posted April 19, 2008 Thanks, that worked! Quote Link to comment https://forums.phpfreaks.com/topic/101883-solved-dynamic-drop-down-menu-not-showing-first-record/#findComment-521517 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.