pioneerx01 Posted December 6, 2010 Share Posted December 6, 2010 Hi, I have a MySQL database called "2011_database" that has a table called "2011_list." In that table I have fields, amongst others, called "name" and "district." I need to find way to get the data from the table and put them into a drop down list on other PHP page. But they need to be listed as "name - district" on one line. I am PHP beginner and if I understand it correctly there need to be two references to get all the data in all records, a third reference to merge them together with " - " in between; and what eludes me the most, putting them in a drop down menu. Any help is greatly appreciated Thanks Link to comment https://forums.phpfreaks.com/topic/220860-how-to-properly-get-data-from-database-and-dump-it-into-dropdown-menu/ Share on other sites More sharing options...
Rifts Posted December 6, 2010 Share Posted December 6, 2010 <?php mysql_connect('server', 'username', 'password') or die('Can not connect 1'); mysql_select_db('2011_database') or die('Can not connect 2'); $sql = mysql_query("SELECT * FROM 2011_list"); echo "<select name=\"DROPDOWN">\n"; echo "<option value=\"NULL\">Select Value</option>\n"; while($r = mysql_fetch_assoc($sql)){ echo "<option value=\"$row['whatever']\">$row['name']."-".$row['district']</option>\n"; } echo "</select>"; ?> somthing like that Link to comment https://forums.phpfreaks.com/topic/220860-how-to-properly-get-data-from-database-and-dump-it-into-dropdown-menu/#findComment-1143677 Share on other sites More sharing options...
litebearer Posted December 6, 2010 Share Posted December 6, 2010 Grrrr - slow typist here as links... (psuedo code) connect to db $query = "SELECT * FROM 2011_list"; $result = mysql_query($query); while($row=mysql_fetch_array($result)) { $display = $row['name'] . " - " . $row['district']; ?> <a href="url_to_where_ever.php?id=<? echo $row['id']; ?>"><?PHP echo $display; ?></a><br> <?PHP } ?> Link to comment https://forums.phpfreaks.com/topic/220860-how-to-properly-get-data-from-database-and-dump-it-into-dropdown-menu/#findComment-1143684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.