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> 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"; 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 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>"; } ?> 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. 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> 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! 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
Archived
This topic is now archived and is closed to further replies.