当我运行Product.php
模型文件时出现此错误,我收到此错误
CDbCommand无法执行SQL语句:SQLSTATE [42S22]:找不到列:1054 未知栏' product_profile.price'在' where子句'。执行的SQL语句是: SELECT COUNT(*)FROM
product
t
INNER JOIN产品ON product_profile.product_id = t.product_id WHERE product_profile.price> = 0 AND product_profile.price< = 100
查询代码在
之下if (!empty($_POST['price'])) {
$price = explode(",", $_POST['price']);
$criteria = new CDbCriteria;
$criteria->select = 'product_profile.price,product_profile.product_id';
$criteria->join.='INNER JOIN product ON product_profile.product_id = t.product_id';
$criteria->condition = " product_profile.price BETWEEN 1 AND 100";
// $criteria->condition = 'product_profile.price >=0 AND product_profile.price <=100';
$criteria->addInCondition("product_profile.price",$price);
}
答案 0 :(得分:3)
您正在使用product
表加入product
,因此找不到product_profile
正确的sql应该是
SELECT COUNT(*)
FROM product t
INNER JOIN product_profile ON product_profile.product_id = t.product_id
WHERE
product_profile.price >=0 AND product_profile.price <=100
以下
$criteria->join.='INNER JOIN product ON product_profile.product_id = t.product_id';
应该是
$criteria->join.='INNER JOIN product_profile ON product_profile.product_id = t.product_id';
答案 1 :(得分:0)
您需要通过Yii ORM更改SQL语法。你的最终查询应该是这样的:
SELECT COUNT(*) FROM product t
INNER JOIN product_profile
ON product_profile.product_id = t.product_id
WHERE product_profile.price >=0 AND product_profile.price <=100
这意味着你需要加入product_profile表,而不是产品表
答案 2 :(得分:0)
如果其他专栏找到了,但是一个 - 没有。 这是代码。
$pages = Yii::app()->db->createCommand()
->select('*')
->from('sk_subj_img_links')
->where('subj_clas=:subj', array(':subj'=>'math-1'))
->queryAll();
然后我收到错误:CDbCommand无法执行SQL语句:SQLSTATE [42S22]:找不到列:1054未知列&#39; subj_clas&#39;在&#39; where子句&#39; 但是如果这个代码
$pages = Yii::app()->db->createCommand()
->select('*')
->from('sk_subj_img_links')
->where('id=:tid', array(':tid'=>’1'))
->queryAll();