i made a search, for my website, and i have a slight problem becuase i cant get it to search more then a single field.
$query = "select * from data where title like \"%$trimmed%\"
order by ID desc";
right now, it only searches the field named title, but i need it to search several more, about 13-15 in all.......how will i go baout doing this?
php/mysql search engine problem
Moderator: General Moderators
-
GandalfTheBrown
- Forum Newbie
- Posts: 1
- Joined: Fri Aug 08, 2003 12:52 pm
The SELECT part of the mysql query string only specifies which columns to return. The WHERE clause specifies where to look.
So you need to add a bunch of WHERE's and OR's:
This doesn't identify which column was matched in any particular result row - you might not need to do that.
LIKE is a "loose" search which returns suffixes and prefixes - $trimmed = 'buff'; would also return buffy, rebuffed etc. An RLIKE search cuts these out - see mysql manual, mysql.com, or post again if you can't find that bit (the manual search leaves a lot to be desired, at least in the version I've got).
So you need to add a bunch of WHERE's and OR's:
Code: Select all
<?php
$query = "SELECT * FROM data WHERE title LIKE '%" . $trimmed . "%' OR col2 LIKE '%" . $trimmed . "%' OR col3 LIKE '%" . $trimmed . "%' OR ..etc"
echo $query; #debug line - helps to check syntax - remove later
?>LIKE is a "loose" search which returns suffixes and prefixes - $trimmed = 'buff'; would also return buffy, rebuffed etc. An RLIKE search cuts these out - see mysql manual, mysql.com, or post again if you can't find that bit (the manual search leaves a lot to be desired, at least in the version I've got).