php - CAKEPHP 2.0, fill find condition array with variable conditions -


i making filter 1 of views. want fill conditions array based on if/else statements check data received url.

i trying build this. creating multiple if/else statements. if statement true want condition filled demonstrated below, else keep condition empty. find() query in else statement being ran , creating error.

//$set , $kleur variables come url, work public function seriesfilter($foil='search', $color, $set, $name){     $this->loadmodel('cards');     $this->loadmodel('magicsets');     $setname = $this->magicsets->findbycode($set);     $this->card->recursive=-1;     $this->layout = 'ajax';      $kleur = "%".$color."%";     $condition = "'manacost like' => $kleur";      $conditions = array(         'set' => $set,         $condition     );       if ($foil == 'nonfoil'){         if($color == 'all'){         $cards= $this->cards->find('all',array('fields'=>'multiverseid,name,nprice,nstock,set,rarity','conditions'=>array('set' => $set),'limit'=>750));         }         else{             $cards= $this->cards->find('all',array('fields'=>'multiverseid,name,nprice,nstock,set,rarity','manacost','conditions' => $conditions,'limit'=>750));         }     } 

below can see error receive

error: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near '=> %r% limit 750' @ line 1  sql query: select `cards`.`multiverseid`, `cards`.`name`, `cards`.`nprice`, `cards`.`nstock`, `cards`.`set`, `cards`.`rarity` `magicmm`.`cards` `cards` `set` = 'bng' , 'manacost like' => %r% limit 750 

any in setting multiple conditions great. want add conditions conditions array received through url.

kind regards,

nick

there should 's like condition. try -

$condition = "manacost '%$kleur%'";  $conditions = array(     'set' => $set,     0 => $condition ); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -