2013-01-24 131 views
2

你知道我如何在cakephp中使用幫助器查找來執行此查詢嗎?如何在cakephp中執行此查詢

$req = "SELECT * FROM brand 
     WHERE nom LIKE '$nom%' AND 
       genre LIKE '$genre%' AND  
       mouvement LIKE '$mouvement%' AND 
       forme LIKE '$forme%' AND 
       prix >= '$mini' AND 
       prix <= '$maxi' 
     ORDER BY prix ASC"; 

我做這樣的事情,但它不工作

$results=$this->Model->find('all',array('conditions'=>array 
    ('AND'=>array('name LIKE'=>$nom,'genre LIKE'=>$genre, 
    'mouvement LIKE'=>$mouvement,.....)))); 

預先感謝您的回覆;-)

回答

1

嘗試這個

$this->Brand->find('all',array 
(
    'conditions' => array 
    (
     'Brand.nom LIKE' => "{$nom}%", 
     'Brand.genre LIKE' => "{$genre}%", 
     'Brand.mouvement LIKE' => "{$mouvement}%", 
     'Brand.forme LIKE' => "{$forme}%", 
     'Brand.prix >=' => $mini, 
     'Brand.prix <=' => $maxi 
    ), 
    'order' => array('Brand.prix' => 'ASC') 
));
+0

讓我知道如果不行的話。 –