Rifts Posted November 25, 2009 Share Posted November 25, 2009 Hey guys im trying to create a dropdown box which is populated by my database of members here is the code i have so far, right now it is only displaying 1 member instead of all of them. also in the end i would like the drop down values to be "Membername(data joined)" <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("clients", $con); $extract = mysql_query ("SELECT * FROM members"); $numrows = mysql_num_rows ($extract); echo"Select USER: <select name='site'>"; while ($row = mysql_fetch_assoc($extract)) { $site = $row['firstname']; } echo"<option name='$site'>$site</option> "; ?> Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/ Share on other sites More sharing options...
dbillings Posted November 25, 2009 Share Posted November 25, 2009 <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("clients", $con); $extract = mysql_query ("SELECT * FROM members"); $numrows = mysql_num_rows ($extract); echo"Select USER: <select name='site'>"; while ($row = mysql_fetch_assoc($extract)) { echo"<option name='$row['firstname']>$row['firstname']</option> "; } ?> Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965169 Share on other sites More sharing options...
dbillings Posted November 25, 2009 Share Posted November 25, 2009 woops <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("clients", $con); $extract = mysql_query ("SELECT * FROM members"); $numrows = mysql_num_rows ($extract); echo"Select USER: <select name='site'>"; while ($row = mysql_fetch_assoc($extract)) { echo"<option name='$row['firstname']'>$row['firstname']</option> "; } ?> Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965177 Share on other sites More sharing options...
Rifts Posted November 25, 2009 Author Share Posted November 25, 2009 im getting "Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\homepage\work.php on line 18" line 18 is echo"<option name='$row['firstname']>$row['firstname']</option> "; so i changed the line to this : echo"<option name='$row[firstname]>$row[firstname]</option> "; and the drop box works now but it only shows the first member and no one else Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965202 Share on other sites More sharing options...
Cosizzle Posted November 25, 2009 Share Posted November 25, 2009 try this echo '<option name="'.$row['firstname'].'">'.$row['firstname'].'</option>'; Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965206 Share on other sites More sharing options...
Rifts Posted November 25, 2009 Author Share Posted November 25, 2009 thank you that worked perfectly Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965211 Share on other sites More sharing options...
Rifts Posted November 25, 2009 Author Share Posted November 25, 2009 how would i arrange them by newest to oldest using another column in my database (i have a column which saves the date they sign up) Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965214 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 how would i arrange them by newest to oldest using another column in my database It should be order by newest, descending if you have a auto-incrementing column in your `members` table. If not, add a column to your `members` table, call it `userid`, set it to INT with a length of 10, and select it auto-increment and make it a primary key. Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965216 Share on other sites More sharing options...
Rifts Posted November 25, 2009 Author Share Posted November 25, 2009 I do have that set already and when I go to the drop down box its not ordered like that its order like this oldest next newest Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965218 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 Try this: $extract = mysql_query ("SELECT * FROM members" ORDER BY `userid` DESC); `userid` of course being the name of the column in which you store your user-IDs in. Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965222 Share on other sites More sharing options...
Rifts Posted November 25, 2009 Author Share Posted November 25, 2009 that is perfect thank you so much Link to comment https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/#findComment-965224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.