# search module

**URL:** <https://www.phphelp.com/t/search-module/10284>\
**Category:** Beginners - Learning PHP\
**Created:** [September 4, 2007, 6:05pm UTC](https://www.phphelp.com/t/search-module/10284 "2007-09-04T18:05:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![theBrent](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@theBrent](https://www.phphelp.com/u/theBrent)\
**Post date:** [September 4, 2007, 6:05pm UTC](https://www.phphelp.com/t/search-module/10284/1 "2007-09-04T18:05:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Q1712](https://www.phphelp.com/letter_avatar_proxy/v4/letter/q/a183cd/32.png) [@Q1712](https://www.phphelp.com/u/Q1712)\
**Post date:** [September 4, 2007, 6:40pm UTC](https://www.phphelp.com/t/search-module/10284/2 "2007-09-04T18:40:56Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![theBrent](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@theBrent](https://www.phphelp.com/u/theBrent)\
**Post date:** [September 4, 2007, 7:20pm UTC](https://www.phphelp.com/t/search-module/10284/3 "2007-09-04T19:20:11Z")

</div>

thanks this also helps… at least i have displayed something…😃

---

<div class="post-metadata">

**Author:** ![Q1712](https://www.phphelp.com/letter_avatar_proxy/v4/letter/q/a183cd/32.png) [@Q1712](https://www.phphelp.com/u/Q1712)\
**Post date:** [September 4, 2007, 10:25pm UTC](https://www.phphelp.com/t/search-module/10284/4 "2007-09-04T22:25:39Z")

</div>

$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.

---

<div class="post-metadata">

**Author:** ![Q1712](https://www.phphelp.com/letter_avatar_proxy/v4/letter/q/a183cd/32.png) [@Q1712](https://www.phphelp.com/u/Q1712)\
**Post date:** [September 4, 2007, 10:35pm UTC](https://www.phphelp.com/t/search-module/10284/5 "2007-09-04T22:35:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![theBrent](https://www.phphelp.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@theBrent](https://www.phphelp.com/u/theBrent)\
**Post date:** [September 5, 2007, 4:45am UTC](https://www.phphelp.com/t/search-module/10284/6 "2007-09-05T04:45:55Z")

</div>

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]()
