By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,885 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,885 IT Pros & Developers. It's quick & easy.

php & mysql puzzle

P: 1
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 &nbsp; ($cata, $catb, $catc, $catd, $cate)</td></tr>\n";

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

Mar 14 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,584
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.
Mar 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.