| 
 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] 
 |