簡體   English   中英

使用join命令對不同的城市值進行代碼初始化

[英]Codeigniter distinct city values using join command

我想從table_1那里獲得post_id ,其中User_id = 5 (它是65 ),然后我想從table_2獲得城市名 ,其中post_id = 65並區分城市值。 我使用codeigniter。 您能否檢查下面的代碼並幫助我找到錯誤:

 public function get_city_list($user_id) {

$this->db->distinct();
$this->db->select('table_2.city');
$this->db->from('table_2');
$this->db->where('table_2.post_id=table_1.post_id');
$this->db->join('table_1','table_1.user_id = $user_id');
$query = $this->db->get();

}
$this->db->select('table_2.city');
$this->db->from('table_1');
$this->db->where('table_1.user_id',$user_id);
$this->db->join('table_2','table_1.post_id=table_2.post_id');
$this->db->get();

這將完成您的工作; 並且不要立即開始編寫復雜的查詢。 從簡單開始。 讀得好,寫得好

如果您想要與眾不同的城市,請嘗試此

$this->db->distinct();
$this->db->get('table_2');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM