frainbreeze
Technical User
hello
i've not had to join up more than 2 tables before, and i've had a look around but i cant seem to find anything on how to do this properly..
i have 3 tables:
suppliers: supplier_ID, supplier_name, contact_name
(table)
------------------
1 supplier1 joe
2 supplier2 bob
3 supplier3 moe
sc_link: sc_link_ID, supplier_ID, category_ID
(table)
------------------
1 1 1
2 2 2
3 3 1
categories: category_ID, category_name
(table)
------------------
1 Balloons
2 Posters
sidenote:
and FYI on my form i have:
<select name="SearchCategory"> where all options are
<options value="category_ID"> Category_name</options>
this is all filled in via a loop in php. Grabbing this value is not the problem (if it were then im in the wrong forum..).
i want to display all suppliers that are in a certain category depending on what is selected from the dropdown. For example, if the user selects "Balloons" from the dropdown and submits, it should return
supplier1
supplier3
pretty basic right? not for me! i have tried:
which returns an error message of: Unknown column 'sc_link.category_ID' in 'where clause'
and i have tried:
which returns an error message of: You have an error in your SQL syntax near 'ON suppliers.supplier_ID = sc_link.supplier_ID JOIN categories ON sc_link.s' at line 2
does anyone know how i can join 3 tables in one statement? or where i'm going wrong? and to think, this is just the beginning...somewhere in the future it looks like i may have to join like 5-7 tables or something like that. so
any help (or even general directions to somewhere else that'd help) are much appreciated
thanks
frainbreeze
i've not had to join up more than 2 tables before, and i've had a look around but i cant seem to find anything on how to do this properly..
i have 3 tables:
suppliers: supplier_ID, supplier_name, contact_name
(table)
------------------
1 supplier1 joe
2 supplier2 bob
3 supplier3 moe
sc_link: sc_link_ID, supplier_ID, category_ID
(table)
------------------
1 1 1
2 2 2
3 3 1
categories: category_ID, category_name
(table)
------------------
1 Balloons
2 Posters
sidenote:
and FYI on my form i have:
<select name="SearchCategory"> where all options are
<options value="category_ID"> Category_name</options>
this is all filled in via a loop in php. Grabbing this value is not the problem (if it were then im in the wrong forum..).
i want to display all suppliers that are in a certain category depending on what is selected from the dropdown. For example, if the user selects "Balloons" from the dropdown and submits, it should return
supplier1
supplier3
pretty basic right? not for me! i have tried:
Code:
SELECT suppliers.supplier_name, sc_link_id, categories.category_name
FROM suppliers, sc_link, categories
WHERE (suppliers.supplier_ID = sc_link.supplier_ID AND sc_link.category_ID = categories.category_ID AND `categories.category_ID` = '$matchthis')
and i have tried:
Code:
SELECT suppliers.supplier_name, sc_link.sc_link_id, categories.category_name FROM suppliers JOIN sc_link
ON suppliers.supplier_ID = sc_link.supplier_ID JOIN categories
ON sc_link.supplier_ID = categories.category_ID
WHERE `category_ID` like '%$matchthis%'";
does anyone know how i can join 3 tables in one statement? or where i'm going wrong? and to think, this is just the beginning...somewhere in the future it looks like i may have to join like 5-7 tables or something like that. so
any help (or even general directions to somewhere else that'd help) are much appreciated
thanks
frainbreeze