Solved

Help with Categories and Subcategories

Posted on 2007-03-17
2
1,030 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
2 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 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

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now