Forum Moderators: coopster
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>