如何下拉子类别匹配数据codeigniter

how to droupdown subcategory mathch data codeigniter

foreach($Portfolio_cat as $row_2)
{           
    #if($row['cid']==$row_2['cid']) 
    echo '<option value="'.$row_2->cid.'" selected>'.$row_2->cname.'</option>';         
}

这样试试

foreach($Portfolio_cat as $row_2){ ?>            
<option <?php if($row['cid']==$row_2['cid']){ echo selected="selected";} ?> value="<?= $row_2->cid ?>"><?= $row_2->cname ?></option>;         

foreach($Portfolio_cat as $row_2)
{           
   if($row['cid']==$row_2['cid']){
      $selected = 'selected="selected"';
   }else{
      $selected = '';
   } 
   echo '<option '.$selected.' value="'.$row_2->cid.'" selected>'.$row_2->cname.'</option>';         
}