Re: Search problem

From: Date: Sun, 22 May 2005 05:27:00 +0000
Subject: Re: Search problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-215711@lists.php.net to get a copy of this message
On Sat, May 21, 2005 1:35 pm, virtualsoftware@gmail.com said: > 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 You can use http://php.net/strlen to determine if the user has typed anything into any given INPUT. Or, if you want a "simple" search with only one INPUT, something like: $query = "select product_id from products where 1 = 0 "; $words = explode(' ', $input); while (list(, $word) = each($words)){ $query .= " or title like '%$word%' "; $query .= " or description like '%$word%' "; . . . } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#215711) next »