Welcome to WebmasterWorld Guest from 54.167.157.247

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Order by 2 Variables in Drop Down List

Changing drop down lists to order by category then subcategory.

   
6:06 pm on Sep 1, 2004 (gmt 0)

10+ Year Member



I am working on a MySQL database. I am a TOTAL beginner. I have a form - a drop down list - and I want it to order by category immediately followed by any subcategories the primary category may have.

In my database, I have the primary links_cat. Inside links_cat are the id and sub_cat columns. If it is a primary field, it has a unique id assigned and '0' in the sub_cat column. If it is a subcategory, it is also assigned a unique id but in the sub_cat field, it shows the id of the primary category.

links_cat

id sub_cat
1 0
2 0
3 1

so id #3 is actually a subcategory of id#1

In my drop down list, I would like for it to order the primary categories by 'id' but I want each subcategory to mmediately follow its primary category.

<td class="bodymd"><span style="color:#336633;">*</span>Category Level:<br />
<select name="sub_cat">
<?php
echo "<option value=\"0\"> Top-Level Category</option>";
$result=MySQLQuery("select * from links_cat ORDER BY id",$QueryError_Email,$QueryError_Browser);
while($row=mysql_fetch_array($result))
{
$temp_id=$row["id"];
$temp_name=addslashes($row["name"]);
if($temp_id==$sub_cat){$selected=" selected";}else{$selected="";}
echo "<option value=\"$temp_id\"".$selected."> $temp_name</option>";
}
?>
</select>

12:57 am on Sep 2, 2004 (gmt 0)

10+ Year Member



Sunflake welcome to WebmasterWorld!

I am not sure I understand exactly what you are asking for. If I understand correctly you want it to be ordered something like this:


1 0
3 1
2 0
4 2
5 0
6 5

Is that what you are referring too or am I missing what you are asking still?
3:50 am on Sep 5, 2004 (gmt 0)

10+ Year Member



Thank you for your response. Yes, you got it. That is exactly what I want. I can't figure it out. And if you can help me, I will worship the ground you walk on! (well, and then I would have another question on how to get the front page which detects how many links are in a category to include in that total the links that are in the subcategories, but thats a question for another day)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month