|
Posted by Guillermo Rauch on 03/13/05 21:14
> 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.'%' );
Navigation:
[Reply to this message]
|