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> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
flappy_warbucks Posted August 28, 2011 Share Posted August 28, 2011 don't forget to click 'solved' Quote Link to comment 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.