Jump to content

how to display a specific category's subcategories within array??


mac007

Recommended Posts

Hi, all:

 

Need help...

I am trying to make it so that if some clicks on a specific category (in this case "clothing" category), it then echoes it's subcategories, but I want it to show it within the main "categories" array list. Right now, it displays/repeats the subcategory within each category, obvioously cause the if statement gets repeated in the while loop... hoe can I make it so the clothing "subcategories" only show within the "clothing" category area??

 

thanks!!

 

 


<?php $query_categories = mysql_query("SELECT * FROM category");
while ($row = mysql_fetch_array ($query_categories)) 
{
echo "<a href='workCategories.php?category=" . $row['category']. "'>" . $row['category']. "</a><br />";

///// here is IF "clothing" category is selected show the "clothing subcategories (cat_id = 1)" 
if ($_GET['category']=='clothing') {
$query_subcategories = mysql_query("SELECT * FROM subcategory WHERE cat_id = 1");
while ($row = mysql_fetch_array ($query_subcategories)) 
{
echo "<a href='workCategories.php?category=" . $row['subcategory']. "'>" . $row['subcategory']. "</a><br />";
}
} 
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.