You are here: Re: [PHP] A little disturbing query !!! « PHP « IT news, forums, messages
Re: [PHP] A little disturbing query !!!

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация