SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Igloo's Avatar
    Join Date
    Dec 2002
    Location
    Australia
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Category & Sub-Cateogry ordering

    Well, I have a MySQL Database with the following structure:

    PHP Code:
    category
    --------------
    id |  name  description  orderby
    ------------------------------------
    1  first  first ones   |   1
    2  
    second second ones  |   2


    subcategory
    --------------
    id |  name  description orderby parent
    --------------------------------------------
    1  games  All games   |   1     |   -1
    2  
    movies All movies  |   1     |   1
    3  
    people All people  |   1     |   2
    4  
    music  All music   |   2     |   
    Basically, from that information I need a function that can do something like this with output in HTML:

    PHP Code:
    ---------------------------------------------
    |
    Games (Lone category/subcategory)          |
    ---------------------------------------------
    |
    First (Category)                           |
    ---------------------------------------------
    |
    Movies (Subcategory of First)              |
    ---------------------------------------------
    |
    Second (Category)                          |
    ---------------------------------------------
    |
    People (Subcategory of Second)             |
    ---------------------------------------------
    |
    Music (Subcategory of Second)              |
    --------------------------------------------- 
    Basically, the orderby column in both tables (category, subcateogry) dictates in which order they will go in; 1,2,3 etc.

    The parent column in the subcategory table is the id number of a category, in which subcategories would go into. If this value of parent equals "-1" then it has no category and is in fact a lone subcategory/category, that will display normally ordered by the orderby function.

    It is sort of like the way a vBulletin and other forum software works in displaying forums and categories.

    Any help is appreicated,
    Thanks.
    Last edited by Igloo; Dec 31, 2002 at 17:35.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why two tables?
    (When one is all you need: http://www.sitepointforums.com/showt...970#post642970)

    Sql examples, tree structures:
    http://www.sitepointforums.com/showt...threadid=86795


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •