这是我的代码我正在使用yii框架。
如何为Category表显示category_name的所有Sub类别?
[这是包含项目的类别表] [1]
[这是子类别表,其中包含来自类别表的cat_id和merchant_id的项目] [2]
[这就是我想要它展示但我不知道如何从category表格中获取类别表格] [3]
[https://i.stack.imgur.com/ZZlrx.png][1]
[https://i.stack.imgur.com/XKyhb.png][2]
Name Categery Name
Sub Cat测试-----------------类别名称 - 不显示
子猫2测试---------------类别名称 - 不显示
public function subCategoriesList()
{
$mtid=Yii::app()->functions->getMerchantID();
$slug=$this->data['slug'];
$stmt="
SELECT sub_id, cat_id, merchant_id, sub_category_name FROM
{{sub_categories}}
WHERE
merchant_id='".Yii::app()->functions->getMerchantID()."'
ORDER BY cat_id DESC
";
$connection=Yii::app()->db;
$rows=$connection->createCommand($stmt)->queryAll();
if (is_array($rows) && count($rows)>=1){
foreach ($rows as $val) {
/*$date=date('M d,Y G:i:s',strtotime($val['date_created']));
$date=Yii::app()->functions->translateDate($date);*/
$date=FormatDateTime($val['date_created']);
if (!empty($val['photo'])){
$img=Yii::app()->request->baseUrl."/upload/$val[photo]";
$photo="<img class=\"uk-thumbnail uk-thumbnail-mini\" src=\"$img\" >";
} else $photo='';
$cat_id=Yii::app()->functions->getCategories(1);
$feed_data['aaData'][]=array(
$chk,stripslashes($val['sub_category_name']).$option,
stripslashes("Category Name - Not Showing"),
$photo,
"$date<br/><span class=\"tag ".$val['status']."\">".t($val['status'])."</span>"
);
}
$this->otableOutput($feed_data);
}
$this->otableNodata();
}
答案 0 :(得分:0)
$stmt="SELECT *
FROM {{sub_categories}}
LEFT JOIN {{category}} ON
{{sub_categories}}.cat_id={{category}}.cat_id
WHERE
{{sub_categories}}.merchant_id={{category}}.merchant_id
ORDER BY {{sub_categories}}.cat_id DESC";