Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Search query conditions

Hi, I have three conditions in search weather the condition will come or not, how to write condition for this please help me

$sessionid=$this->request->getQuery("sessionid");
$listingid=$this->request->getQuery("listingid");
$userid=$this->request->getQuery("userid");

 $parameters = $this->persistent->parameters;
 if (!is_array($parameters)) {
 $parameters = array();
 }

 if($sessionid){
 $parameters["conditions"] = 'sessionid = '.$sessionid;
 }
  if($listingid){
 $parameters["conditions"] = 'listingid = '.$listingid;
 }
  if($sessionid){
 $parameters["conditions"] = 'userid = '.$userid;
 }
 $parameters["order"] = "id";
 $parameters["columns"] = 'id,name,status,is_featured';

 $users = Users::find($parameters);


33.6k
Accepted
answer
edited Jul '15

Using an AND?

if (!is_array($parameters)) {
 $parameters = array();
 }

$conditions = array();
 if($sessionid){
$conditions[] = 'sessionid = '.$sessionid;
 }
  if($listingid){
$conditions[] = 'listingid = '.$listingid;
 }
  if($sessionid){
$conditions[] = 'userid = '.$userid;
 }

 if (count($conditions)) {
     $parameters['conditions'] = join(' AND ', $conditions);
 }

Hi,

Thanks its working.

How can i use OR, IN, BETWEEN in this. please tell me it will be very useful for my project