query to search field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
eltonpiko
Forum Commoner
Posts: 31
Joined: Wed Apr 01, 2009 2:19 pm

query to search field

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: query to search field

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
eltonpiko
Forum Commoner
Posts: 31
Joined: Wed Apr 01, 2009 2:19 pm

Re: query to search field

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: query to search field

Post 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%'";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply