what do u wanna list, whats ur tablestructure.
as i understood u want a product list, and display all products of a categorie if a category is entert ???
as i don’t know ur table and fieldnames u need to adjust this, but this should be what u are looking for:
SELECT * FROM `pd`, `cat` WHERE `pd`.`cat_id`=`cat`.`id` AND (`pd_name` LIKE "%serchtextenterd%" OR `pd_name` LIKE "%serchtextenterd%") ORDER BY ...
a little tip: if u run a select from multible tables just imagen there is a new table buil containing al combinations of row in all tables.
that means if u have one table with 3 rows and one with 2 rows all 6 posible combinations are in that “imagined” new table, even those that dont make any sence.
and then u just use the WHERE to shrink it down to the needed.
e.g.:
pd:
id | cat_id | pd_name
1 | 1 | name one
2 | 1 | second name
3 | 1 | another product
4 | 2 | the last entry
cat:
id | cat_name
1 | the first cat
2 | an other cat
then u imagen a combined table is created:
pd.id | pd.cat_id | pd.pd_name | cat.id | cat.cat_name
1 | 1 | name one | 1 | the first cat
2 | 1 | second name | 1 | the first cat
3 | 1 | another product | 1 | the first cat
4 | 2 | the last entry | 1 | the first cat
1 | 1 | name one | 2 | an other cat
2 | 1 | second name | 2 | an other cat
3 | 1 | another product | 2 | an other cat
4 | 2 | the last entry | 2 | an other cat
u see there are a lot of useless rows.
then u use WHERE pd
.cat_id
=cat
.id
and u get the onece belonging togther
:
pd.id | pd.cat_id | pd.pd_name | cat.id | cat.cat_name
1 | 1 | name one | 1 | the first cat
2 | 1 | second name | 1 | the first cat
3 | 1 | another product | 1 | the first cat
4 | 2 | the last entry | 2 | an other cat
and then u may use AND (pd_name
LIKE “%other%” OR pd_name
LIKE “%other%”)
an u will end up with…
pd.id | pd.cat_id | pd.pd_name | cat.id | cat.cat_name
3 | 1 | another product | 1 | the first cat
4 | 2 | the last entry | 2 | an other cat
…as the result of ur query
hope this helps