Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在codeigniter中编写查询,结果与要求的不同_Codeigniter - Fatal编程技术网

在codeigniter中编写查询,结果与要求的不同

在codeigniter中编写查询,结果与要求的不同,codeigniter,Codeigniter,我正在研究codeigniter,并编写以下查询: $this->db->select('*'); $this->db->from('tbl_profile'); $this->db->join('tbl_msg', 'tbl_msg.msg_sender_id = tbl_profile.profile_id'); $this->db->order_by("msg_id", "desc"); $query = $this->db->g

我正在研究codeigniter,并编写以下查询:

$this->db->select('*');
$this->db->from('tbl_profile');
$this->db->join('tbl_msg', 'tbl_msg.msg_sender_id = tbl_profile.profile_id');
$this->db->order_by("msg_id", "desc");
$query = $this->db->get('', $config['per_page'], $this->uri->segment(3));
$data['records'] = $query->result_array();
select * from tbl_profile as A
join (select * from tbl_msg) as B on A.profile_id = B.msg_sender_id
相应地,我得到以下结果:

SELECT (*) FROM tbl_profile
JOIN tbl_msg ON tbl_msg.msg_sender_id = tbl_profile.profile_id
这返回了错误的结果,因为我需要与以下查询对应的结果:

$this->db->select('*');
$this->db->from('tbl_profile');
$this->db->join('tbl_msg', 'tbl_msg.msg_sender_id = tbl_profile.profile_id');
$this->db->order_by("msg_id", "desc");
$query = $this->db->get('', $config['per_page'], $this->uri->segment(3));
$data['records'] = $query->result_array();
select * from tbl_profile as A
join (select * from tbl_msg) as B on A.profile_id = B.msg_sender_id

请帮助

首先,您缺少order by子句,但我想,您的意思是其他差异

如果您需要,可以使用此查询,什么将返回准确的代码:

$this->db->select('*', FALSE);
$this->db->from('tbl_profile as A');
$this->db->join('( select * from tbl_msg ) as B', 'A.msg_sender_id = B.profile_id');
$this->db->order_by("msg_id", "desc");
$query = $this->db->get('', $config['per_page'], $this->uri->segment(3));
$data['records'] = $query->result_array();
来自codeigniter用户手册:

$this->db->select()

接受可选的第二个参数。若您将其设置为FALSE,CodeIgniter将不会尝试用反勾号保护您的字段或表名。如果您需要复合select语句,这将非常有用。

您可能有输入错误(mse\u sender\u id/msg\u sender\u id)。
那是干什么的?我已经纠正了这个错误,甚至编辑了上面的文章。我使用两个查询得到了不同的结果。上面的查询工作得很好,但没有分页。它只能从数据库中获取93条记录。相反,如果我在MySql控制台中编写查询结果(我指的是MySql查询),那么我总共获得295条记录。请帮忙。但是有页码和没有页码的代码是什么?你能从中得到多少结果?