[英]CAKEPHP 2.0, fill find condition array with variable conditions
我目前正在針對我的一種觀點進行過濾。 我想基於if/else
語句填充條件數組, 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接收到的conditions數組中。
親切的問候,
缺口
應該有'
S表示LIKE
條件。 嘗試-
$condition = "manaCost like '%$kleur%'";
$conditions = array(
'set' => $set,
0 => $condition
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.