Find categories that have a information in them

Discussion in 'PHP' started by drewbe121212, May 12, 2006.

  1. #1
    Hi all! I have a database with the setup

    cat_id | cat_name | cat_parent

    that is pretty self explanitory, as I am sure we have all been on the subcategory programming before

    Now, I have another table items

    item_id | item_name | item...... | item_category

    when browsing a particular category, I get the items by finding item_category = current category


    Now, I need to compile a directory list from the root
    with only the categories that have values.

    So lets say i have
    cars
    -- mazda
    -- chevy
    trucks
    -- chevy
    -- GMC
    -- Duramax

    Lets say the only two categories that have values are cars->mazda
    and
    trucks->gmc->duramax

    How would I get the values from only these two categories?

    I have been up and down this, will little to no luck at all.

    If anyone knows of a tutorial, or helpfull code, please feel free to leave it

    Thank you,
    Drew
     
    drewbe121212, May 12, 2006 IP
  2. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #2
    The only way u would know if values existed(dynamicly anyhow) is by quering it. So just loop through the results

    if($value !=""){
    //Value exists Do something
    }
     
    Big 'G', May 12, 2006 IP
  3. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Hmm, not quite.

    After playing around a bit, I have ended up an array containing only the categories that the item is in...

    I am going to change this to just a programming standpoint to make it easier to read...
    
    Array
    (
        [0] => Array
            (
                [1] => Design And Development
                [3] => Programming
                [16] => PHP
                [total_tutorials] => 2
            )
    
        [1] => Array
            (
                [1] => Design And Development
                [3] => Programming
                [19] => Coldfusion
                [total_tutorials] => 1
            )
    
    Code (markup):
    This is becoming the hard part now... maybe I just need to take a break with it...

    I would want it to come out like this:

    If I am in the root directory

    root/design and development (tutorials: 3)

    If I am in the programming directory

    root > design and development > programming (3)

    If i am in the PHP directory:

    root > design and development > programming > PHP (2)

    Etc, do you see what I am trying to accomplish. Now that I have the array of the breadcrumbs to and the count of tutorials existing, it is simply the issue of combining the data as to not display it twice depending on which category I am currently at.

    Any help/suggestions ?
     
    drewbe121212, May 12, 2006 IP