We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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);


34.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