繁体   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