分页问题? [英] problem with pagination?
问题描述
我使用codeigniter
为什么我的代码不能工作 $ this-> pagination-> create_links()
?
问题1:我遇到此错误:
遇到PHP错误
严重性:注意
消息:未定义变量:offset
文件名:admin / accommodation.php
行号:45 $问题2:点击$ this-> b > pagination-> create_links()
,更改网址,但不会更改内容表 .i使用XAMPP
我该怎么办?
我的代码:
function show()
{
// load pagination class
$ this-> load-> library('pagination');
$ config ['base_url'] = base_url()。'admin / accommodation / show';
$ config ['total_rows'] = $ this-> db-> count_all('hotel_submits');
$ config ['per_page'] ='2';
$ this-> pagination-> initialize($ config);
$ data ['pagination'] = $ this-> pagination-> create_links();
$ offset =(int)$ offset; //只是为了确保这里没有什么有趣的东西
$ data ['results'] = $ this-> db-> query(SELECT @rownum:= @ rownum + 1 rownum,t。 。
FROM(SELECT @rownum:= 0)r,hotel_submits t。
ORDER BY id desc LIMIT $ offset,2);
$ this-> load-> view('admin / accommodation_submit_show',$ data);
}
对于
解决方案您在未定义的查询中使用的变量
$ offset
您必须以方法参数传递,或使用$ this-> uri-> segment(n)
。
您是否阅读了有关创建jquery分页的答案?
您必须将$ offset传递给您的方法:
function show($ offset = 0)
{
//代码在这里
}
假设您在名为admin的文件夹中安装了Codeigniter,并且您的控制器的名称为accommodation。在这种情况下,你必须像这样设置
$ config ['base_url']
:$ config ['base_url'] ='accommodation / show';
编辑:
如果管理员不是您安装Codeigniter的文件夹,而是您的 controllers 文件夹中的住宿控制器在其中,则您必须使用此:
$ config ['base_url'] ='admin / accommodation / show ';
$ config ['uri_segment'] = 4;
i use of codeigniter
Why not work
$this->pagination->create_links()
in my code?
Problem 1: I have this error:A PHP Error was encountered Severity: Notice Message: Undefined variable: offset Filename: admin/accommodation.php Line Number: 45
Problem 2: After click on
$this->pagination->create_links()
, change url, but does not change content table.i use of XAMPPWhat do i do?
my code:
function show() { // load pagination class $this->load->library('pagination'); $config['base_url'] = base_url().'admin/accommodation/show'; $config['total_rows'] = $this->db->count_all('hotel_submits'); $config['per_page'] = '2'; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links(); $offset = (int) $offset; // just to make sure nothing funky gets in here $data['results'] = $this->db->query("SELECT @rownum:=@rownum+1 rownum, t.* ". "FROM (SELECT @rownum:=0) r, hotel_submits t ". "ORDER BY id desc LIMIT $offset, 2"); $this->load->view('admin/accommodation_submit_show', $data); }
With respect
解决方案The variable
$offset
that you're using in your query in undefined. You have to pass it in as a method parameter, or use$this->uri->segment(n)
.Have you read my answer on create jquery pagination?
You have to pass $offset to your method:
function show($offset = 0) { // code goes here }
I'll assume you have an installation of Codeigniter in a folder called "admin", and your controller's name is "accommodation". In that case you have to set
$config['base_url']
like this:$config['base_url'] = 'accommodation/show';
EDIT:
If admin is not the folder you've installed Codeigniter in, but rather a folder inside your controllers folder which has the accommodation controller in it, then you'll have to use this:
$config['base_url'] = 'admin/accommodation/show'; $config['uri_segment'] = 4;
这篇关于分页问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!