?
Solved

Help with Categories and Subcategories

Posted on 2007-03-17
2
Medium Priority
?
1,056 Views
Last Modified: 2013-12-24
Need help outputting Categories and Subcategories.  I read some helpful information from this link on EE.  
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_22132013.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 );      
0
Comment
Question by:e4art
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 1500 total points
ID: 18743287
I can't help with the code as you've cross posted in the CF Server and I don't do php but...

best practice would be to have 3 tables...mixing category types in a single table could be difficult

catID
CatName

SubCatID
SubCatName
CatID

SubSubCatID
SubSubCatName
SubCatID


then you as you drilled down you queries would be something like this

show all
select * from Cats

Show Single Cat and it's subcats
select *.cats, *.subcats from cats c inner join subcats sc on c.catid = sc.catid
where catid = phpvariable

Show Single subCat and it's subsubcats
select *.subcats, *.subsubcats from subcats c inner join subsubcats sc on c.subcatid = sc.subcatid
where subcatid = phpvariable


get the idea?

0
 

Author Comment

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

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question