Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

php - problem with pagination?

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 XAMPP

What 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...