Re: A little disturbing query !!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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.'%' );

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux