php & mysql puzzle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lynnem
    New Member
    • Mar 2007
    • 1

    php & mysql puzzle

    Hi there,
    I'm new to php & mysql and would really appreciate some help with the following:

    I'd like to display a list of products and a string showing the categories they fall into:
    - a product can be in 0 - 5 categories
    - the products table holds five columns for each potential category
    - each category column can hold a code (foriegn key)
    - the category code is the primary key in the category table
    - the category table has a column for the category name (e.g., 'dark', 'milk', 'white', 'fruit', 'nuts')

    I would like to display:
    ChoccySelect - dark, fruit, nuts
    ChunkChocbar - milk, nuts
    ChoccyChoccyDee lite - dark, milk, white, fruit

    but have only managed
    ChoccySelect - 01, 04, 05
    ChunkChocbar - 02, 05
    ChoccyChoccyDee lite - 01, 02, 03, 04


    my code is:
    $tresults = @mysql_query('S ELECT g.product_name, g.cat_1, g.cat_2, g.cat_3, g.cat_4, g.cat_5, t.cat_code, t.cat_desc FROM products g LEFT JOIN cat_lookup t ON t.cat_code IN (g.cat_1, cat_2, cat_3, cat_3, cat_4, cat_5) ORDER BY product_name');


    while ($tresult = mysql_fetch_arr ay($tresults)) {
    $tcode = $tresult['cat_code'];
    $gname = $tresult[‘product_name'];
    $cata = $tresult['cat_1'];
    $catb = $tresult['cat_2'];
    $catc = $tresult['cat_3'];
    $catd = $tresult['cat_4'];
    $cate = $tresult['cat_5'];


    echo "<tr><td>$g name &nbsp; ($cata, $catb, $catc, $catd, $cate)</td></tr>\n";

    (I wasn't kidding when I said I was new to this!)

    Thanks,
    L.
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    please re-submit this post with the complete PHP script, and MySQL DB script.
    What ever the thing in your original post is too complex to understand.
    and please wrap the codings with the relevant tags.

    Comment

    Working...