Re: Search problem
| From: | Joe Wollard | Date: | Mon, 23 May 2005 01:35:52 +0000 |
| Subject: | Re: Search problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-215718@lists.php.net to get a copy of this message | ||
I used to search the same way until someone on this list mentioned using a fulltext index in mysql. Doing this almost eliminated all my headaches with searching.
Easiest way to create a fulltext index is to use phpMyAdmin. Once you've created the fulltext index on
title,description,price,weight you can then search all columns (much faster than the other way I might add) by using a simply SQL query such as this:
$sql = "SELECT * FROM products WHERE MATCH(title,description,price,weight) AGAINST ('" . mysql_escape_string($_GET['query']) . "')";
More on FULLTEXT can be found here: http://dev.mysql.com/doc/mysql/en/fulltext-search.html
Hope that helps!
-Joe W.
www.joewollard.com <http://www.joewollard.com>
virtualsoftware@gmail.com wrote:
Hi, I need to build up a search module for a shop. If I make a basic search (product title for example) it is ok. $query = "SELECT product_id FROM products WHERE title LIKE '%$title%'"; But i need an advance search for more than one field (title, description, price, weight) The problem is that i don't know which field is filled in by the user (title, description, price or weight) I mean, the user can fill in all fields, or only price field, or title and weight etc How can i do the search? Thanks