Mewsta Posted February 26, 2007 Share Posted February 26, 2007 Hi guys, Im new to PHP so was wondering if anyone can help me, i need to get my php page to display data from a table in a combo box. Also if there are more than 1 entry the same, then not to duplicate. Can you help?! Quote Link to comment https://forums.phpfreaks.com/topic/40231-solved-combo-box/ Share on other sites More sharing options...
JBS103 Posted February 26, 2007 Share Posted February 26, 2007 Do you have any code written? If you give us some code we can give you a specific solution to how you should/can do things. The best we can do right is form you a concept and some pseudo code. I'm thinking that you can get all the data from the database into an array. From there, use the array_unique function to get rid of any duplicates. From there, you can run a loop (based on the number of results; using count or something of the like) that will create the HTML needed to form the combo box you want. Quote Link to comment https://forums.phpfreaks.com/topic/40231-solved-combo-box/#findComment-194640 Share on other sites More sharing options...
craygo Posted February 26, 2007 Share Posted February 26, 2007 <select name=mycomboname> <?php $combo = "SELECT DISTINCT(name_field) AS name, id FROM tablename"; $res = mysql_query($combo) or die(mysql_error()); while($r = mysql_fetch_assoc($res)){ echo "<option value=\"".$r['id']."\">".$r['name']."</option>\n"; } ?> </select> Substitute the field names and the value of each option to fit your needs Ray Quote Link to comment https://forums.phpfreaks.com/topic/40231-solved-combo-box/#findComment-194673 Share on other sites More sharing options...
Mewsta Posted February 27, 2007 Author Share Posted February 27, 2007 Ray, many thanks for this! I have got this working! Quote Link to comment https://forums.phpfreaks.com/topic/40231-solved-combo-box/#findComment-195175 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.