Click to See Complete Forum and Search --> : Search query


raj_2006
10-14-2007, 09:07 AM
Hi All,

I have written a query for a search.A search keyword is coming by post method and I have to search wether this word match with any field in 1st table(if found then search in 2nd table) tables ie 1.Member 2.Pet

In 'member' table there is mid,username a primary autoincrement field and in pet table there are mid and pid where pid is primary autoincrement field.Now if i get "raj" as keyword from the post then i am searching it in the table member as username and if i get any corresponding mid then I am searching in pet table that how many pets this mid have currently.

member table:

1.mid
2.username

pet table

1.pid
2.mid
3.pname

I am using this query:

$sql=mysql_query("select * from pet,member where (member.username='$keyword' or member.username like '$keyword%' )and member.mid=pet.mid") or die(mysql_error());

First I would like to search the member table if record is found then based on mid I like to search pet table.basically 2 queries can work but I want to combine those in a single query.

Please suggest.

Thanks for your co-operation in advance.

Regards,
Raj