CAKEPHP 2.0,用可变条件填充查找条件数组
我目前正在为我的一个观点制作一个过滤器。我想根据检查从url收到的数据的CAKEPHP 2.0,用可变条件填充查找条件数组,php,arrays,cakephp,find,conditional-statements,Php,Arrays,Cakephp,Find,Conditional Statements,我目前正在为我的一个观点制作一个过滤器。我想根据检查从url收到的数据的if/else语句填充条件数组 我试着把它建成这样。我将创建多个if/else语句。如果该语句为true,我希望按照下面的说明填充条件,否则将保持条件为空。正在运行else语句中的find()查询并创建错误 //$set and $kleur are variables that come from the URL, they work public function seriesfilter($foil='search',
if/else
语句填充条件数组
我试着把它建成这样。我将创建多个if/else
语句。如果该语句为true,我希望按照下面的说明填充条件,否则将保持条件为空。正在运行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接收的条件数组添加条件
亲切问候,
尼克对于
类
条件,应该有
s。试试-
$condition = "manaCost like '%$kleur%'";
$conditions = array(
'set' => $set,
0 => $condition
);
对于
类
条件,应该有”
s。试试-
$condition = "manaCost like '%$kleur%'";
$conditions = array(
'set' => $set,
0 => $condition
);
我有一个问题,类名的第一个字母应该大写是真的吗?或者它不再重要了?(在php中)TNX我们应该遵循约定。对于2.x来说,CakePHP正常工作是很重要的。哇,脚本现在可以工作了!谢谢。我尝试了许多变体,但我不确定如果引号来自变量,find查询将如何读取它们。我有一个问题,类名的第一个字母是否应该大写?或者它不再重要了?(在php中)TNX我们应该遵循约定。对于2.x来说,CakePHP正常工作是很重要的。哇,脚本现在可以工作了!谢谢。我尝试了许多变体,但我不确定如果引号来自变量,find查询将如何读取它们。