Jezreel Posted May 19, 2006 Share Posted May 19, 2006 Ok.. I am a beginner at Php/MySql, however most of the time I can feel my way around in the dark. However, trying to do this sort of hurts my head.I need to have a drop down list which retrieves the data for the drop down list from a MySql Database.The data is in a table that will constantly be growing so obviously the items in the drop down list will grow as well. So the table is called "Songs" and the field is s_title. When the drop down list retreives the data I need it to place the songs in alphabetical order as well.Any takers?Thanks in advance,Jezreel Link to comment https://forums.phpfreaks.com/topic/10013-brainteaser-for-phpmysql-guru-please-help/ Share on other sites More sharing options...
fenway Posted May 20, 2006 Share Posted May 20, 2006 Well, a simple MySQL query can retrieve the fields in whatever order you desire, and I'm sure there are literally hundreds of tutorials on how to dump these results via PHP into a drop-down / combobox / whatever. Link to comment https://forums.phpfreaks.com/topic/10013-brainteaser-for-phpmysql-guru-please-help/#findComment-37439 Share on other sites More sharing options...
Duncan Disorderly Posted June 22, 2006 Share Posted June 22, 2006 JezreelI am a noobie too but here is the method I used to create something similar, I assume your songs table has id, s_title columnsThis works for me so I hope this helps...but with some luck someone will come along and explain a more elegant method.Kind regardsDD<?[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// config connection to dbase[!--colorc--][/span][!--/colorc--]$dbhost='localhost';$dbusername='XXXX';$dbuserpass='XXXX';$dbname='XXXX';[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// connect to dbase[!--colorc--][/span][!--/colorc--]$conn = mysql_connect ($dbhost, $dbusername, $dbuserpass);[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// check connection[!--colorc--][/span][!--/colorc--]if (!mysql_select_db($dbname)) die(mysql_error());[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]//query setup[!--colorc--][/span][!--/colorc--]$sql="SELECT id, s_title FROM Songs ORDER BY s_title ASC";$result=mysql_query($sql);?>[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// the line below identifies the dropdown[!--colorc--][/span][!--/colorc--]<select id="ST_DD" name="ST_DD"><?$options="";[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// loop to insert values into dropdown[!--colorc--][/span][!--/colorc--]while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $title=$row["s_title"]; $options.="<OPTION VALUE=\"$id\">".$title.'</option>';}?>[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]//Display the Dropdown[!--colorc--][/span][!--/colorc--]<?php echo $options ?></select> Link to comment https://forums.phpfreaks.com/topic/10013-brainteaser-for-phpmysql-guru-please-help/#findComment-48407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.