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 />";
}
} 
}
?>

Link to comment
Share on other sites

OK, got it.. if it helps anybody:

 

I added to the if statement:

 

if (($_GET['category']=='clothing') && ($row['category']=='clothing'))

 

and now the subcategory appears only in the "clothing" section of the array

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.