todayme Posted March 4, 2007 Share Posted March 4, 2007 I have been looking around the internet for an example of what I need to do but cant find anything was wondering if someone here might be able to help. What I need to do is to connect to a mysql db select a table and then a field from that table and put all the contents of that field into a dropdown box. Anyone got any sugestions? Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/ Share on other sites More sharing options...
Yesideez Posted March 4, 2007 Share Posted March 4, 2007 Something like this: <select name="names"><?php $query=mysql_query("SELECT name FROM table ORDER BY name ASC"); while ($fetch=mysql_fetch_assoc($query)) { echo '<option value="'.$fetch['name'].'">'.$fetch['name'].'</option>'; }?></select> Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199430 Share on other sites More sharing options...
WebDevon Posted March 4, 2007 Share Posted March 4, 2007 this is how I do it: <select size="1" name="txtRecall" style="font-family: Arial Unicode MS; font-size: 10px"> <?php mysql_select_db("database_name") or die(mysql_error()); $result = mysql_query("SELECT * FROM tblName") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $Item_ID = $row['ID']; $Name = $row['Name']; ?> <option value="<?=Item_ID?>"><?=$Name?></option> <? } ?> </select> Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199432 Share on other sites More sharing options...
Yesideez Posted March 4, 2007 Share Posted March 4, 2007 Well, does that work for you or are you having problems with it? Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199442 Share on other sites More sharing options...
WebDevon Posted March 4, 2007 Share Posted March 4, 2007 dont know who your referencing but mine works just fine. Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199450 Share on other sites More sharing options...
Yesideez Posted March 4, 2007 Share Posted March 4, 2007 hahahaha sorry I got very confused there Ignore me, having a thicko moment Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199455 Share on other sites More sharing options...
todayme Posted March 4, 2007 Author Share Posted March 4, 2007 Sorry just got some visitors, back to again just about to try it............ I am in the midle of designing the database relationships. Will update you soon as I have tried it. Buy the way your help is really appreciated. Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199475 Share on other sites More sharing options...
todayme Posted March 5, 2007 Author Share Posted March 5, 2007 I have done this cond with your example but have a problem with it... any comments on what the problem may be? <? $dbhost = "localhost"; $dbuser = "admin_sex"; $dbpass = "sex"; $dbname = "admin_sex"; $db = mysql_pconnect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname) or die(mysql_error()); <select name="names"> $query=mysql_query("SELECT name FROM _Industries"); while ($fetch=mysql_fetch_assoc($query)) { echo '<option value="'.$fetch['Industry'].'">'.$fetch['Industry'].'</option>'; }</select> ?> Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199489 Share on other sites More sharing options...
todayme Posted March 5, 2007 Author Share Posted March 5, 2007 Okay I am trying this now no errors but also no data in the drop down box ha ha......any ideas lol <? $dbhost = "localhost"; $dbuser = "admin_sex"; $dbpass = "sex"; $dbname = "admin_sex"; $db = mysql_pconnect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname) or die(mysql_error()); ?> <select name="names"><?php $query=mysql_query("SELECT name FROM _Industries"); while ($fetch=mysql_fetch_assoc($query)) { echo '<option value="'.$fetch['Industry'].'">'.$fetch['Industry'].'</option>'; }?></select> Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199499 Share on other sites More sharing options...
todayme Posted March 5, 2007 Author Share Posted March 5, 2007 I worked it out, lol eye for detail today isnt good. Probabley helps when you get the syntax I learned in VB ha ha Thanks guys really appreciated. Link to comment https://forums.phpfreaks.com/topic/41172-populating-dropdown-box/#findComment-199502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.