2017-06-21 4 views
0

CodeIgniterでの結合でDistinctを使用するにはどうすればよいですか?顧客の名前と登録されたカテゴリを取得しようとしていますが、カテゴリを使用していますが、別のものを使用しましたが、あいまいなフィールドエラーが発生しました。どのようにこの問題を解決できますか。 マイビューcodeigniterの結合で明白です

<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

これを使って、カテゴリごとに1つのデータが得られます。これは私のために働いていません。 –

+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

私は結果のスクリーンショットを添付しました。私はサブカテゴリのために重複データを取得しています。これをどのように解決できますか? –

関連する問題