homepage Welcome to WebmasterWorld Guest from 54.161.240.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Order by 2 Variables in Drop Down List
Changing drop down lists to order by category then subcategory.
Sunflake




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

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>

 

Knowles




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

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?

Sunflake




msg:1297984
 3:50 am on Sep 5, 2004 (gmt 0)

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)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved