我想从table_1获取post_id,其中User_id=5(它是65),然后我想要从table_2获取城市名称,其中post_id=65并区分城市值。我使用代码点火器。您能检查一下我下面的代码并帮我找出错误吗:
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');
关于php - 使用 join 命令 Codeigniter 不同的城市值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25708304/