Hi Folks,
How would I be able to echo Data from the database considering the situation:
There is a List of MAIN Categories in one DB table
There is another DB table that contains the SUB CATEGORIES
I want to be able to echo a div that displays each MAIN CATEGORY only once and display all the appropriate SUB CATEGORIES below it.... this must be done in a loop (while or for or whatever) because I have a lot of MAIN CATEGORIES. Below is a sample HTML of what I want to achieve:
<div id="1">
<p>ICE CREAM FLAVORS</p>
<p>
1. Chocolate
2. Strawberry
3. Vanilla
</p>
</div>
<div id="2">
<p>PIZZA FLAVORS</p>
<p>
1. All Veggies
2. Hawaiian
3. Meat Lovers
</p>
</div>
<div id="3">
<p>MAIN CATEGORY #3</p>
<p>
1. Sub Category #1
2. Sub Category #2
3. Sub Category #3
</p>
</div>
How do I do this without using IF and ELSE?
Below is a sample of the code I usually use to display multiple items using while()
$query = "SELECT * FROM main_category, sub_category ORDER BY main_category.category_name ASC";
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo '<div><a href="next.php">' . $row['category_name'] . '</a></div>';
} // Close While
By the way, I also want to follow the following order/sort:
1. DIVs for the MAIN CATEGORIES will be arranged by name of the MAIN CATEGORY
2. Inside each DIV, I want to sort the SUB CATEGORIES again by name
I think this is simple enough but I just dunno how to do this. Hope anybody there can help asap.
Thanks in Advance!!!