search module

i have here a search module that should display the following:
cat_name(category name)
pd_name(product_name)

but i find it hard on query for 2 tables. when a client types either product or category it should display something. anyone has ideas about this?

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

thanks this also helps… at least i have displayed something…:smiley:

$username = “*******”; // change this to your username
$password = “*****”; // change this to your password

are these ur real password and username? if this is the case u should edit ur entry an repalace them with stars like i did here.

i’m not very good at SQL.
i have no idea how to do this with an SQL statment.
i would just use multible statments to grab the cats first.

but there has to be a better way.

hope somebody else here is able to answer ur question.

nope those were just an example for the username and password…

ok sir,i hope that someone would lend a hand… thanks again sir! :D

Sponsor our Newsletter | Privacy Policy | Terms of Service