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 Quote Link to comment 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 Quote Link to comment 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 } ?> Quote Link to comment 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.