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
ChoccyChoccyDeelite - dark, milk, white, fruit
but have only managed
ChoccySelect - 01, 04, 05
ChunkChocbar - 02, 05
ChoccyChoccyDeelite - 01, 02, 03, 04
my code is:
$tresults = @mysql_query('SELECT 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_array($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>$gname ($cata, $catb, $catc, $catd, $cate)</td></tr>\n";
(I wasn't kidding when I said I was new to this!)
Thanks,
L.