Jump to content


Brainteaser for Php/MySql Guru - Please help.

  • Please log in to reply
2 replies to this topic

#1 Jezreel

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 May 2006 - 04:22 PM

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,


#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 May 2006 - 03:33 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Duncan Disorderly

Duncan Disorderly
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationBirmingham UK

Posted 22 June 2006 - 08:43 AM


I am a noobie too but here is the method I used to create something similar, I assume your songs table has id, s_title columns

This works for me so I hope this helps...but with some luck someone will come along and explain a more elegant method.
Kind regards

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// config connection to dbase[!--colorc--][/span][!--/colorc--]

[!--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";

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// the line below identifies the dropdown[!--colorc--][/span][!--/colorc--]
<select id="ST_DD" name="ST_DD">

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]// loop to insert values into dropdown[!--colorc--][/span][!--/colorc--]
while ($row=mysql_fetch_array($result)) {

$options.="<OPTION VALUE=\"$id\">".$title.'</option>';
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]//Display the Dropdown[!--colorc--][/span][!--/colorc--]
<?php echo $options ?>

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users