Re: A little disturbing query !!!
| From: | Guillermo Rauch | Date: | Sun, 13 Mar 2005 19:14:10 +0000 |
| Subject: | Re: A little disturbing query !!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210615@lists.php.net to get a copy of this message | ||
> Hello,
Hi,
> $query = "SELECT * FROM templates where ".$_POST[searchtype]." LIKE
> '%".$_POST[searchterm]."%'";
Although it works, always put the array index as a string between quotes.
$_POST[searchterm] to $_POST['searchterm']
>
> But now I need the search to be more advanced, the user may enter a
> price range to find results within a range of two numbers, I have added
> to the form two textfields the first for the low price ($lprice) the
> second for the high price ($hprice).. the 'price' field is located in
> the same table (templates).
You can start with a basic query like
$sql = 'SELECT * FROM
templates WHERE price < %s AND
price > %s
AND %s LIKE '%s';
If there's no start price, you put in the query price + 1, as
price will be always lower than price + 1.
if(!_POST['sprice'] ) {
$sprice = 'price + 1;
}
And the same with endprice ($eprice)..
Then you replace the %s
$sql = sprintf( $sql, $sprice, $eprice, $a, '%'.$b.'%' );