Solved

Help with Categories and Subcategories

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WSUS Client Issues 52 1,637
Google Crawl Errors Producing 404 Errors 4 83
Need to Configure Debug Diag 2.2 for IIS 7.5 to capture dump files 1 67
PHP Register global 21 87
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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