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

nested loop, 2 MySQL tables

P: n/a
I have a set of nested links, and at one time each category one had all the
same subcategories. Now that has changed - each category has different
subcategories. I have a tree menu, but now it just shows all subs under
each category, of course. I have 2 tables - one for categories, one for
subcategories - they are related by the categoryID. I think I have the SQL
fine (have tried several different versions - see most recent/uncluttered
below), but how do I get it to work correctly in the tree loop?

SELECT DISTINCT cat.catName, cat.catDesc, subcat.subcatName
FROM cat, subcat
WHERE cat.catID = subcat.catID;

Tree example:
cat.catName(1)
subcat.subcatName(1)
subcat.subcatName(2)

cat.catName(2)
subcat.subcatName(3)
subcat.subcatName(4)
I'm sure it must be simple, and I'm just having a slow brain day...

Thanks,
Chris
Jun 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chris wrote:
I have a set of nested links, and at one time each category one had
all the same subcategories. Now that has changed - each category has
different subcategories. I have a tree menu, but now it just shows
all subs under each category, of course. I have 2 tables - one for
categories, one for subcategories - they are related by the
categoryID. I think I have the SQL fine (have tried several
different versions - see most recent/uncluttered below), but how do I
get it to work correctly in the tree loop?
SELECT DISTINCT cat.catName, cat.catDesc, subcat.subcatName
FROM cat, subcat
WHERE cat.catID = subcat.catID;

Tree example:
cat.catName(1)
subcat.subcatName(1)
subcat.subcatName(2)

cat.catName(2)
subcat.subcatName(3)
subcat.subcatName(4)
I'm sure it must be simple, and I'm just having a slow brain day...

Thanks,
Chris


Does this help:
http://dev.mysql.com/tech-resources/...ical-data.html
Jun 14 '06 #2

P: n/a
SELECT cat.catName, cat.catDesc, subcat.subcatName
FROM cat
LEFT JOIN subcat ON subcat.catID = cat.catID
ORDER BY catID ASC

--
http://blog.deshot.com
http://www.padbuilder.com

Chris wrote:
I have a set of nested links, and at one time each category one had all the
same subcategories. Now that has changed - each category has different
subcategories. I have a tree menu, but now it just shows all subs under
each category, of course. I have 2 tables - one for categories, one for
subcategories - they are related by the categoryID. I think I have the SQL
fine (have tried several different versions - see most recent/uncluttered
below), but how do I get it to work correctly in the tree loop?

SELECT DISTINCT cat.catName, cat.catDesc, subcat.subcatName
FROM cat, subcat
WHERE cat.catID = subcat.catID;

Tree example:
cat.catName(1)
subcat.subcatName(1)
subcat.subcatName(2)

cat.catName(2)
subcat.subcatName(3)
subcat.subcatName(4)
I'm sure it must be simple, and I'm just having a slow brain day...

Thanks,
Chris


Jun 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.