jaylam13 Posted August 28, 2011 Share Posted August 28, 2011 Hi. I am using this script to populate a dropdown list box from sql, it works but does anyone know how to sort the list in alphabetical order? $sql="SELECT * FROM Fish WHERE ***** = '".$_GET['stocktype']."'"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $ID=$row["ID"]; $Stock=$row["Commonn"]; $Options.="<OPTION VALUE=\"$ID\">".$Stock; } <SELECT NAME='stock1'> <OPTION VALUE='$Options'>$Options</option> </SELECT> Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/ Share on other sites More sharing options...
flappy_warbucks Posted August 28, 2011 Share Posted August 28, 2011 Yea. $sql="SELECT * FROM Fish WHERE ***** = '".$_GET['stocktype']." order by fish asc;'"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $ID=$row["ID"]; $Stock=$row["Commonn"]; $Options.="<OPTION VALUE=\"$ID\">".$Stock; } <SELECT NAME='stock1'> <OPTION VALUE='$Options'>$Options</option> </SELECT> That should call the fish in alphabetical order. Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262886 Share on other sites More sharing options...
jaylam13 Posted August 28, 2011 Author Share Posted August 28, 2011 Sorry that didnt work error: [phpBB Debug] PHP Warning: in file /home/****/****.com/**/***.php on line 128: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262887 Share on other sites More sharing options...
flappy_warbucks Posted August 28, 2011 Share Posted August 28, 2011 yea, a mistake in the SQL syntax. Revised: $sql="SELECT * FROM Fish WHERE ***** = '".$_GET['stocktype']."' order by fish asc;"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $ID=$row["ID"]; $Stock=$row["Commonn"]; $Options.="<OPTION VALUE=\"$ID\">".$Stock; } <SELECT NAME='stock1'> <OPTION VALUE='$Options'>$Options</option> </SELECT> Although, it being an sql error, it would be ideal if you could find it yourself Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262888 Share on other sites More sharing options...
jaylam13 Posted August 28, 2011 Author Share Posted August 28, 2011 yea, a mistake in the SQL syntax. Revised: $sql="SELECT * FROM Fish WHERE ***** = '".$_GET['stocktype']."' order by fish asc;"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $ID=$row["ID"]; $Stock=$row["Commonn"]; $Options.="<OPTION VALUE=\"$ID\">".$Stock; } <SELECT NAME='stock1'> <OPTION VALUE='$Options'>$Options</option> </SELECT> Although, it being an sql error, it would be ideal if you could find it yourself That gave the same error and didnt populate the dropdown box. Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262889 Share on other sites More sharing options...
flappy_warbucks Posted August 28, 2011 Share Posted August 28, 2011 yea, a mistake in the SQL syntax. Revised: $sql="SELECT * FROM Fish WHERE ***** = '".$_GET['stocktype']."' order by fish asc;"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $ID=$row["ID"]; $Stock=$row["Commonn"]; $Options.="<OPTION VALUE=\"$ID\">".$Stock; } <SELECT NAME='stock1'> <OPTION VALUE='$Options'>$Options</option> </SELECT> Although, it being an sql error, it would be ideal if you could find it yourself That gave the same error and didnt populate the dropdown box. Yea, i just noticed what i have done there. Where it says: "order by fish asc;" in the SQL statement, change the word "fish" to what you want the database to order the results by. As i don't know your columns i cant suggest what one. Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262891 Share on other sites More sharing options...
jaylam13 Posted August 28, 2011 Author Share Posted August 28, 2011 Just as I hit reply I realised the same, thanks its working perfectly now. Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262892 Share on other sites More sharing options...
flappy_warbucks Posted August 28, 2011 Share Posted August 28, 2011 don't forget to click 'solved' Link to comment https://forums.phpfreaks.com/topic/245896-dropdown-list-from-mysql/#findComment-1262895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.