-1

This is my Code I am using yii framework.

how do I show all the Sub category with category_name for the Category table ?

[This is the Category Table with the items][1]

[This is the Sub Category Table with the items it has the cat_id and merchant_id from the Category Table][2]

[And This is What i want it to show but i don't how to get the category_name form the Category table][3]

[https://i.stack.imgur.com/ZZlrx.png][1]

[https://i.stack.imgur.com/XKyhb.png][2]

Name                        Categery Name   
  1. Sub Cat Testing-----------------Category Name - Not Showing

  2. Sub cat 2 testing---------------Category Name - Not Showing

    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();
    }
    
joe mrema
  • 1
  • 6

1 Answers1

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";
joe mrema
  • 1
  • 6