SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help sorting data

    Hello,
    I have two tables.
    One table has 2 fields
    categoryid, categoryname.

    Table 2 has 3 fields
    subcategoryid, subcategoryname, parentid.

    Obviously table 2 is holding sub categories for table 1.

    Question is how do I query this to show this data in this format.
    Is this done on the MySQL side or PHP side? Really confused on this.

    What is this called?

    category name 1
    -----------------sub cat1 (parent is 1)
    -----------------sub cat2 (parent is 1)
    -----------------sub cat 3 (parent is 1)


    category name 2
    -----------------sub cat4 (parent is 2)
    -----------------sub cat5 (parent is 2)

    Thanks!

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you search the forum for Category and Subcategory to see how many threads there have been on the topic?

    Note that the query itself is handled in the database and, depending on the formatting needs, those are handled in your front end application.

    So the specific layout you are looking for is handled in PHP but the query would be used to return the rows and their sub categories.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did do a search but i didnt know the "official term" was category and sub category as the results were not what i was looking for. Ill continue to look. Thanks for your help


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
  •