2017-06-21 86 views
0

如何在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

回答

0

您可以使用下面提及的查詢。

$query = $this->db->group_by('category_master.Category_Id,business_profile_details.Business_Id'); 

請嘗試以上,它會幫助你。

+0

通過使用這我得到每個類別的一個數據。這不適合我。 –

+0

我在這裏添加了截圖鏈接https://i.stack.imgur.com/fEk8Y.png –

+0

@StutiRauthan:很高興幫助你擺脫這個障礙。 –

0

可以使用

然後
$this->db->distinct(); 

有時候不鮮明的作品,你可以使用

$this->db->group_by('business_mapping.unique_coloumn_Name');

+0

如果我使用組,我只能獲取單個數據。 –

+0

我附上了結果的屏幕截圖,由於子類別,我得到重複數據,我該如何解決? –