Search database

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
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Search database

Post by Zeceer »

Hi,

I've made search engine on my webshop that works fine, exept that it's only outputting the rows that have a field matching the search word perfect. Here:

Code: Select all

$result = mysql_query( "SELECT * FROM products WHERE category='".$_POSTї'word']."' OR prodnr='".$_POSTї'word']."' OR product='".$_POSTї'word']."'" );
$word is the search string from the search form. Is there any command in mysql or PHP that will make this string find alle the rows containing a specific word?

Now there is like this, if someone search for "socks" and the there is a field containing "super socks" this does not give a hit. You have to search for the exact word. In this case "super socks".
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Post by ILoveJackDaniels »

instead of category='".$_POST['word']."' try category like '%".$_POST['word']."%'
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Works fine! Thanks! :D
Post Reply