PHP Search Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

PHP Search Query

Post by gotornot »

Hi All.
I am looking to search a database of products based upon someone typing the name of the product they are looking for.
I am using the below SQL request:

Unfortunately this only shows what ever your typing and anything before or after (%) is there any way that it could also search unplaced string instances?
For example
$q = "SELECT * FROM products WHERE prod_name LIKE '%$id%' order by fee asc LIMIT 20";

If i type black ops ps3 it brings back search result until i get to the PS3 part. because entries in the db are "black ops for the PS3" because i havent conformed it says no results.
I need it to show all results.
is there another way? or can someone point me in the right direction?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP Search Query

Post by social_experiment »

What do you store as a "search term", the entire string (black ops ps3) ? You can store variations on the term (black ops, black ops ps3) and then use a LIKE statement to find a match; this will ideally be in a different table than the one you store products in
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply