Buzz: Mysql Execution. Problem With Sub Categories

Discussion in 'PHP' started by bartolay13, Aug 26, 2008.

  1. #1
    i have 2 tables

    1. Categories table
    2. Sub-Categories table

    Just the lamest idea of categories

    There is one main category with about 5 subcategories each
    how can i do the query in one execution?

    currently i have this one:

    select t1.post_categories_name,(select t2.subcategories_name from post_subcategories as t2 where t1.post_categories_id = '1' group by t2.group) as subCategories
    from post_categories as t1 left join post_subcategories as t2 on t1.post_categories_id = t2.subCat_parent_id

    and outputting this:
    Array
    (
    [0] => Array
    (
    [post_categories_name] => Community
    [subCategories] => Before / After Photos
    )
    [1] => Array
    (
    [post_categories_name] => Community
    [subCategories] => Before / After Photos
    )
    [2] => Array
    (
    [post_categories_name] => Community
    [subCategories] => Before / After Photos
    )
    [3] => Array
    (
    [post_categories_name] => Community
    [subCategories] => Before / After Photos
    )

    [4] => Array
    (
    [post_categories_name] => Ebony Skin Secret
    [subCategories] =>
    )

    [5] => Array
    (
    [post_categories_name] => Educational
    [subCategories] =>
    )
    [6] => Array
    (
    [post_categories_name] => Message Board
    [subCategories] =>
    )
    [7] => Array
    (
    [post_categories_name] => Referral Doctor
    [subCategories] =>
    )
    )

    Please note that the query above, on the subquery statement theres a static value of 1. and the query musnt have a static value

    Please help..
     
    bartolay13, Aug 26, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Most sites will do for each subcategory an extra query, it's less intensive to do so..
     
    EricBruggema, Aug 27, 2008 IP