Solved

Help with Categories and Subcategories

Posted on 2007-03-17
2
1,035 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

New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

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…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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.

929 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

10 Experts available now in Live!

Get 1:1 Help Now