Php 使用where条件连接查询代码点火器返回所有行

Php 使用where条件连接查询代码点火器返回所有行,php,mysql,codeigniter,Php,Mysql,Codeigniter,下面是我从两个表中获取数据的连接查询 $this->db->select('*'); $this->db->from('george_hotel_bkd_customers'); $this->db->where('george_hotel_bookings.bookingref',$ref); $this->db->join('george_hotel_bookings', 'george_hotel_bookings.user_id = geo

下面是我从两个表中获取数据的连接查询

$this->db->select('*');
$this->db->from('george_hotel_bkd_customers');
$this->db->where('george_hotel_bookings.bookingref',$ref);
$this->db->join('george_hotel_bookings', 'george_hotel_bookings.user_id = george_hotel_bkd_customers.user_id');    
$query = $this->db->get();
根据我的
where
条件,它只返回一行,但将返回与连接条件匹配的所有行

好像我的where条件没有在这里执行


请帮助我

$ref=是什么,它应该大致拾取多少个结果? 当你忽略where时,你得到了什么?如果得到完整结果,则必须是$ref值的问题,或者,这就是结果

只是一个注释,您不需要选择(*),这是默认值,如果这只是一个示例,很抱歉拾取。你也可以将->from(whaterver\u table)添加到->get(任何你需要添加的表)中->get(),所以为什么不删除->from()行,这只是可读性的选择,但我不知道你可以这样做一段时间,所以我想把它添加到我的答案中

或者另一个问题解决路径是联接是否应作为第三个参数“左”。总是有人加入吗

正如阿南特建议的那样,改变声明中的位置或连接不会产生任何影响

$this->db->select('*');
$this->db->from('george_hotel_bkd_customers');
$this->db->join('george_hotel_bookings', 'george_hotel_bookings.user_id = george_hotel_bkd_customers.user_id');
$this->db->where('george_hotel_bookings.bookingref',$ref);
$query = $this->db->get();

始终where is last

您的问题毫无意义,但请在where子句之前加入。先交换join和where.put join,然后where@Kisaragi尝试了,但没有成功尝试在右联接或左联接之间切换,方法是在调用联接时添加
right
left
作为第三个参数。例如,
$this->db->join('george_hotel_bookings','george_hotel_bookings.user_id=george_hotel_bkd_customers.user_id','right')