Page 1 of 1

query to search field

Posted: Wed Oct 21, 2009 10:05 am
by eltonpiko
hi ive search all the topics but couldn't find my answer sorry if im posting this even if it has been posted before but hope someone can help me out.iv got a search on my site that will connect to my database now ive already add the script to connect to database and everything any it work fine with no error but cant get any result it must be a problem with my query in the script can anyone point me to the right way to do it it.i want my search to search the sql table iv got category in my database called product inside it contain 4 tables tile,image,content and price this is just a simple test after making it work in expand it.so how would i write my query in my php script to search the field for each keyword store in the fields?

$query = "SELECT * FROM `product` WHERE 1 \"%$trimmed%\" i dont think that the right way please help.

thanks

Re: query to search field

Posted: Wed Oct 21, 2009 1:48 pm
by AbraCadaver
Kind of hard to follow. There is info that is backwards or missing:

1. What is the name of the database?
2. What is the name of the table you want to search?
3. What is the name of the field that you want to search?

Re: query to search field

Posted: Wed Oct 21, 2009 11:55 pm
by eltonpiko
the name of the database is test.inside theres table called product and inside product these 4 field title ,image,content,price.i want my database to be able to search all the field in product and output what ever matches the search key words on my result page.now all i get on my page is zero result found and if i dont enter keyword ill get please enter key word witch prove its connecting to my db but my query is wrong so i doesnt no were to search.

Re: query to search field

Posted: Thu Oct 22, 2009 1:24 pm
by AbraCadaver
eltonpiko wrote:the name of the database is test.inside theres table called product and inside product these 4 field title ,image,content,price.i want my database to be able to search all the field in product and output what ever matches the search key words on my result page.now all i get on my page is zero result found and if i dont enter keyword ill get please enter key word witch prove its connecting to my db but my query is wrong so i doesnt no were to search.

Code: Select all

$query = "SELECT * FROM product WHERE title LIKE '%$trimmed%' OR image LIKE '%$trimmed%' OR content LIKE '%$trimmed%' OR price LIKE '%$trimmed%'";