You are here: Re: MySQL PHP and blank paramters « All PHP « IT news, forums, messages
Re: MySQL PHP and blank paramters

Posted by J.O. Aho on 12/04/05 12:01

Homechoice wrote:
> Here bis something that is not working and I cannot figure out why.
>
> I have a mySQL query that is something like
>
> select * from customers where firstname LIKE "%$pram1%" AND town LIKE "%
> $param2".
>
> Providing Param 1 and 2 contain values all is well. However if they are
> blank (which accoring to my logic should mean the like becomes anything)
> it does not work.
>
> Any ideas please? I just want to pass a blank parameter

$query="SELECT * FROM customers";

if(strlen($pram1) || strlen($pram2)) {
$query.=" WHERE ";
if(strlen($pram1)) {
$query.="firstname LIKE '%$pram1%'";
}
if(strlen($pram1) && strlen($pram2)) {
$query.=" AND ";
}
if(strlen($pram2)) {
$query.="town LIKE '%$pram2%'";
}
}

$result=mysql_query($query);


That should fix the problem and only query those things that has been asked
for to look for.


//Aho

 

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

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