Php 查询行号,查询限制失败的内容
我在模型中有两个函数,它们都要求相同的东西,只是第二个函数要求在查询字符串中限制数量和偏移量。我在控制器中调用这两个函数,但只有第一个函数执行我想要的操作,第二个函数返回0Php 查询行号,查询限制失败的内容,php,mysql,codeigniter,Php,Mysql,Codeigniter,我在模型中有两个函数,它们都要求相同的东西,只是第二个函数要求在查询字符串中限制数量和偏移量。我在控制器中调用这两个函数,但只有第一个函数执行我想要的操作,第二个函数返回0 public function get_row_nums() { $commenttb="commenttb"; $membertb="membertb"; $query=sprintf("SELECT `%s`.* FROM `%s` JOIN `%s` ON (`%
public function get_row_nums()
{
$commenttb="commenttb";
$membertb="membertb";
$query=sprintf("SELECT `%s`.* FROM `%s` JOIN `%s` ON (`%s`.userid=`%s`.userid)",
$commenttb,
$commenttb,
$membertb,
$commenttb,
$membertb);
$query=$this->db->query($query);
print_r($query->result_array());
return $query->num_rows();
}
public function get_comments($num,$offset)
{
$commenttb="commenttb";
$membertb="membertb";
$query=sprintf("SELECT `%s`.* FROM `%s` JOIN `%s` ON (`%s`.userid=`%s`.userid) LIMIT %d,%d",
$commenttb,
$commenttb,
$membertb,
$commenttb,
$membertb,
$num,
$offset);
$query=$this->db->query($query);
print_r($query->result_array());
return $query;
}
这是控制器中的函数
public function get_comments()
{
if(!file_exists('application/views/blog/list_comment_view.php'))
{
show_404();
}
else
{
$userid=$this->get_userid();
$row_nums=$this->blog->get_row_nums();
$config['base_url']=base_url().'index.php/blog/list_comment_view';
$config['total_rows']=$row_nums;
print_r($row_nums);
$config['per_page']=5;
$config['num_links']=2;
$config['full_tag_open']='<p>';
$config['full_tag_close']='<p>';
$config['first_link']='First';
$config['last_link']='Last';
$this->pagination->initialize($config);
$data['comments']=$this->blog->get_comments($config['per_page'],$this->uri->segment(3));
$this->load->library('table');
$this->table->set_heading('No','Title','Created','Modified','Action');
$this->load->view('blog/list_comment_view', $data);
}
}
public函数get_comments()
{
如果(!file_存在('application/views/blog/list_comment\u view.php'))
{
show_404();
}
其他的
{
$userid=$this->get_userid();
$row_nums=$this->blog->get_row_nums();
$config['base_url']=base_url().'index.php/blog/list_comment_view';
$config['total_rows']=$row_nums;
打印(行数);
$config['per_page']=5;
$config['num_links']=2;
$config['full_tag_open']='';
$config['full_tag_close']='';
$config['first_link']='first';
$config['last_link']='last';
$this->pagination->initialize($config);
$data['comments']=$this->blog->get_comments($config['per_page'],$this->uri->segment(3));
$this->load->library('table');
$this->table->set_heading('No','Title','Created','Modified','Action');
$this->load->view('blog/list\u comment\u view',$data);
}
}
我已经尝试了一次又一次地检查它,但我仍然不知道在源代码中可能犯了什么错误,即视图在第二次调用模型的第二个函数时只加载了print Array()。我很感激你的帮助
更新:我在配置文件中设置了指向的基本url 我还在Controller中创建了一个名为Blog的文件夹,我在其中存储了所有内容。 我重置了默认路径“/blog/LoginClassName”;
在这一部分之前,一切正常。正确的限制systax
LIMIT OFFSET,LIMIT
因此,您的查询应该如下所示
SELECT commenttb.* FROM commenttb JOIN membertb ON (commenttb.userid=membertb.userid) LIMIT 0,5
这意味着将$query更改为
$query=sprintf("SELECT `%s`.* FROM `%s` JOIN `%s` ON (`%s`.userid=`%s`.userid) LIMIT %d,%d",
$commenttb,
$commenttb,
$membertb,
$commenttb,
$membertb,
$offset,
$num);
$this->uri->segment(3)
的值是多少?生成的查询是什么样子的?您确实应该在这些查询调用上进行一些错误检查。数据库查询并不总是成功的,你知道,即使查询字符串在语法上是完美的。我很确定他们中的任何一个都是错误的,echo$query的结果是什么
在(commenttb
.userid=membertb
限制5,0请稍候,我正在吃午饭