stelthius Posted December 14, 2008 Share Posted December 14, 2008 Hello guys, Im just wondering how would one go about adding all the users in the database into a drop down menu, the reason for this is i have a ban user function but instead of trying to remember the name you cab just click the drop down menu and select the name to ban, Rick Link to comment https://forums.phpfreaks.com/topic/136949-solved-inserting-users-from-a-database-into-a-drop-down/ Share on other sites More sharing options...
T Horton Posted December 14, 2008 Share Posted December 14, 2008 Hi I think something like this would do it: <select name="ID"> <?php $query = "QUERY HERE"; $rs = mysql_query($query); while ($row = mysql_fetch_array($rs)) { echo "<option value='$row[0]'>$row[1]</option>"; } ?> </select> Hope this helps Tom Link to comment https://forums.phpfreaks.com/topic/136949-solved-inserting-users-from-a-database-into-a-drop-down/#findComment-715246 Share on other sites More sharing options...
stelthius Posted December 14, 2008 Author Share Posted December 14, 2008 Hello again, Im not quite sure were im going wrnog but i tried this <? include("include/session.php"); ?> <select name="ID"> <?php $query = "SELECT * FROM `users` WHERE 1 = `username`"; $rs = mysql_query($query); while ($row = mysql_fetch_array($rs)) { echo "<option value='$row[0]'>$row[1]</option>"; } ?> </select> And it doesnt seem to be working, the other methods i have tried just show the md5 passwords lol im new to it so im not exactly sure what else to try with it Link to comment https://forums.phpfreaks.com/topic/136949-solved-inserting-users-from-a-database-into-a-drop-down/#findComment-715295 Share on other sites More sharing options...
Mad Mick Posted December 14, 2008 Share Posted December 14, 2008 Try this if you want username displayed on drop down and id as value posted: <? include("include/session.php"); ?> <select name="ID"> <?php $query = "SELECT id,username FROM users"; $rs = mysql_query($query); while ($row = mysql_fetch_assoc($rs)) { echo "<option value='",$row['id'],"'>",$row['username'],"</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/136949-solved-inserting-users-from-a-database-into-a-drop-down/#findComment-715327 Share on other sites More sharing options...
stelthius Posted December 14, 2008 Author Share Posted December 14, 2008 Ahhh! all so simple, thanks mate its appretiated. Link to comment https://forums.phpfreaks.com/topic/136949-solved-inserting-users-from-a-database-into-a-drop-down/#findComment-715331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.