【发布时间】:2015-09-13 07:10:47
【问题描述】:
我目前正在为我的一种观点制作过滤器。我想根据 if/else 检查从 url 收到的数据的语句填充条件数组。
我正在尝试像这样构建它。我将创建多个if/else 语句。如果语句为真,我希望如下所示填充条件,否则将保持条件为空。 else 语句中的find() 查询正在运行并产生错误。
//$set and $kleur are variables that come from the URL, they 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));
}
}
您可以在下面看到我收到的错误
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=> %R% LIMIT 750' at line 1
SQL Query: SELECT `Cards`.`multiverseid`, `Cards`.`name`, `Cards`.`nprice`, `Cards`.`nstock`, `Cards`.`set`, `Cards`.`rarity` FROM `magicmm`.`cards` AS `Cards` WHERE `set` = 'BNG' AND 'manaCost like' => %R% LIMIT 750
在设置多个条件方面的任何帮助都会很棒。我只想将条件添加到通过 url 接收的条件数组中。
亲切的问候,
尼克
【问题讨论】:
标签: php arrays cakephp find conditional-statements