homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Selecting from three tables

 10:47 am on Sep 30, 2008 (gmt 0)

This is, broadly, the scenario.

Table 1: Associates a product with one category only
prodID, prodName, prodCat etc

Table 2: Stores info about Categories
catID, catName etc

Table 3: Associates products with additional categories and has only two fields
prodID, catID

Table 1 puts a product into its primary category, but Table 3 can associate that product with multiple other cats. So given product ids of, say, aaa, bbb and ccc, and category ids of 1, 2, 3, 4 etc, table three could look like this:

aaa 2
aaa 4
bbb 1
bbb 2
bbb 4
ccc 3
ccc 4

And so on.

What I want to do

For the current product

1. Get additional cats it is in from table three
2. Get the name(s) of those cats from table two
3. Print out the names of those cats

I am lost on quite how to construct the select for this. Anyone?



 11:28 am on Sep 30, 2008 (gmt 0)

select a.catname from table2 a, table3 b where a.catID=b.catID and b.prodID=<current product>


 7:44 pm on Sep 30, 2008 (gmt 0)

Thank you, that got me on track and it's done.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved