The table 'category':
cat_id category
1 mobile
2 watch
.. ..
和 'category_brand' 表:MySQL的加入表和接收一行
product_id cat_id
1 1
2 1
3 2
.. ..
,我有这样的代码
public function actionEdit($id)
{
$sql="SELECT * FROM category_brand INNER JOIN category ON category_brand.cat_id=category.cat_id WHERE category_brand.product_id=$id";
$editcat=Yii::$app->db->createCommand($sql)->queryOne();
print_r($editcat->category);die;
}
我想retreice的PRODUCT_ID的范畴。我在这里做错了什么? product_id是auto_increment值。但我得到“试图获得非对象的特性”如果你想AR对象作为结果
您的查询看起来不错,这将离开谊代码作为该错误的嫌疑。 –