Link to home
Start Free TrialLog in
Avatar of e4art
e4artFlag for United States of America

asked on

Help with Categories and Subcategories

Need help outputting Categories and Subcategories.  I read some helpful information from this link on EE.  
https://www.experts-exchange.com/questions/22132013/Help-with-categories-subcategories.html?sfQueryTermInfo=1+categori+subcategori

I want to do something very similar where I have my top categories, then subcategories, then sub-subcategories.  I have a photo gallery that I built which is close to completion.  What I want to do with it is very close to what this site has. http://creative.gettyimages.com/source/home/home.aspx
My layout is different of course, but the same concept.  Go to the site and click on "Editorial", then scroll over to click on "News", then you will see sub-sub categories of which contain a certain amount of photos.

I have an upload form which works in that you can upload a photo into the parent category.  Guess I'll also need to add a subcategory to that form as well.  My question is how do I set up my tables and call upon them in my script.  Right now I can call up my categories, but it's also calling up my subcategories as well.

Here's what my one table looks like.  Would it be better to set up 2 tables? 1 for Categories and 1 for Subcategories?  Let's get that down first. Then we can deal with adding in those sub-subcategories.  That part might be trick since those will be added dynamically case by case.

  parent_id     category_id      category_name  
      0                 1                    Editorial Features
      0                 2                    Archives
      0                 3                    Photographers
      0                 4                    Advertising / Corporate
      1                 5                    News
      1                 6                    Sports
      1                 7                    Entertainment
      1                 8                    Features
      1                 9                    Portrait
      1                10                   Publicity

So far I only listed my subcategories is relationship to "Editorial."  I have a link on the side of my webpage which when I click on should bring me to these subcategories.  Right now I have it that all come up.  How do I change that.  Should I first create two tables?  HELP PLEASE!!

Here's part of my code:
// Category Listing

        if( empty($cid) && empty($pid) )
        {
                $number_of_categories_in_row = 4;

                $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
                                                FROM gallery_category as c
                                                LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
                                                GROUP BY c.category_id" );
                while( $row = mysql_fetch_array( $result ) )
                {
                        $result_array[] = "<a href='album.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
                }
                mysql_free_result( $result );      
ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of e4art

ASKER

o.k., thanks.  I might have to re-post this question in the PHP area, but I get what you're talking about.