如何在CodeIgniter中使用Distinct加入,我試圖獲取客戶的名稱和註冊類別,但我的問題是獲取數據時,類別,我已經使用不同,但然後我得到曖昧的字段錯誤,我該如何解決這個問題。 我查看不同於加入codeigniter mysql
<table class="table table-hover example1">
<thead>
<tr>
<th>SNo.</th>
<th>Business Name</th>
<th>Category Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php $i=0;
foreach($value as $row){ ?>
<tr>
<td><?php echo ++$i;?></td>
<td><?php echo $row->Bussiness_Name;?></td>
<td><?php echo $row->Category_Name;?></td>
<td onClick="RestoreVendor(<?php echo $row->Business_Id; ?>,<?php echo $row->Trash;?>,'<?php echo $row->Bussiness_Name;?>')" class="btn btn-primary">Remove</td>
</tr>
<?php }?>
</tbody>
</table>
我的控制器:
public function removecategory()
{
$this->load->model('VendorModel');
$data = $this->VendorModel->remove_category();
$this->load->view('admin/remove_cat', array('value'=>$data));
}
我的模型
public function remove_category()
{
$this->db->select('*');
$this->db->distinct('Category_Id');
$this->db->from('business_mapping');
$this->db->join('business_profile_details', 'business_profile_details.Business_Id = business_mapping.Business_Id');
$this->db->join('category_master', 'category_master.Category_Id = business_mapping.Category_Id');
$query = $this->db->get();
return $query->result();
}
結果圖像 enter image description here
通過使用這我得到每個類別的一個數據。這不適合我。 –
我在這裏添加了截圖鏈接https://i.stack.imgur.com/fEk8Y.png –
@StutiRauthan:很高興幫助你擺脫這個障礙。 –