php - CakePHP: How to retrieve data by multiple condition -


please me retrieve data table multiple condition in cakephp
have 1 table name: article; have tried retrieve data code below
want specific id given in parameter; article_price > 0 , article_status > 1

public function getarticle($artid = ''){      return $this->find('all', array(          'condition' => array(                             'article_id =' => $artid,                              'article_price' => '> 0',                             'article_status = ' => '1'),          'order' => 'article_id desc'      )); } 

// out put selected data without condition want.

problem code?
found out print: echo $this->element ('sql_dump'); , got following sql statement:

select `article`.`article_id`, `article`.`name`, `article`.`article_price`, `article`.`article_status` `db_1stcakephp`.`article` `article` 1 = 1 order `article_id` desc 

please me. thank!

if model name article:

public function getarticle($art_id) {     return $this->find('first', array(         'conditions' => array(             'article.article_id' => $art_id,             'article.article_price >' => 0,             'article.article_status >' => 1,         ),     )); } 

using 'model.field' syntax optional, until models have relationship , have same names - example article.status , author.status.

moving comparison sign array's key part allows do:

'article.price >'   => $minprice, 'article.price <='  => $maxprice, 

and didn't notice typo in 'conditions'.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -