我在CakePHP中有这个查询但它无法正常工作。但是我在db中记录了当我删除内部价格条件时它返回结果但是没有使用价格。
SELECT `Car`.`id`, `Car`.`title`, `Car`.`description`, `Car`.`image`, `Car`.`state`,
`Car`.`state_code`, `Car`.`city`, `Car`.`zipcode`, `Car`.`person_name`, `Car`.`email`,
`Car`.`phone`, `Car`.`mobile`, `Car`.`ad_type`, `Car`.`ad_status`, `Car`.`make`,
`Car`.`model`, `Car`.`year`, `Car`.`conditiion`, `Car`.`transmision`, `Car`.`color`,
`Car`.`fuel`, `Car`.`body`, `Car`.`doors`, `Car`.`mileage`, `Car`.`price`,
`Car`.`accessories`, `Car`.`security`, `Car`.`created`, `Car`.`user_id`
FROM `portal_Carsnew`.`cars` AS `Car`
WHERE `Car`.`ad_status` = '1'
AND `Car`.`make` = 'Ferrari'
AND `Car`.`model` = '458 Italia'
AND `Car`.`state` = 'New York'
AND `Car`.`city` = 'Albany' AND ((`Car`.`price` < 95000)
AND (`Car`.`price` > 0))
ORDER BY `Car`.`id`
desc LIMIT 10
答案 0 :(得分:0)
使用cakephp find
方法从表中选择记录
试试下面的代码
$this->Car->find('all', array(
'conditions' => array(
'Car.ad_status' => 1,
'Car.make' => 'Ferrari',
'Car.model' => '458 Italia',
'Car.state' => 'New York',
'Car.city' => 'Albany',
'Car.price >' =>0,
'Car.price <' =>95000
),
'order'=> 'id DESC',
'limit' => 10
));
答案 1 :(得分:0)
试试这个:
$this->Car->find('all', array(
'conditions' => array(
'and' => array(
array('Car.price > ' => 0,
'Car.price < ' => 95000
),
'Car.ad_status' => 1,
'Car.make' => 'Ferrari',
'Car.model' => '458 Italia',
'Car.state' => 'New York',
'Car.city' => 'Albany',
)),
'order'=> 'id DESC',
'limit' => 10
));
答案 2 :(得分:0)
试试这个:
$price = array();
$price['Car.price >'] = 0;
$price['Car.price <'] = 95000;
$this->Car->find('all', array(
'conditions' => array_merge($price,
array(
'Car.ad_status' => 1,
'Car.make' => 'Ferrari',
'Car.model' => '458 Italia',
'Car.state' => 'New York',
'Car.city' => 'Albany',
'Car.price >' => 0,
'Car.price <' => 95000
)
),
'order' => 'Car.id DESC',
'limit' => 10
));