Welcome Guest, Not a member yet? Register   Sign In
Pagination, offset issue
#3

[eluser]1cookie1[/eluser]
[quote author="Gurudutt" date="1263413786"]Hi

I am also new to codeigniter but If you try

$config['query_string_segment'] = 'offset';
$config['page_query_string'] = TRUE;[/quote]

hi Gurudutt

the code above produces a php notice: undefined constant 'query_string_segment' and 'page_query_string'.

One way to get it working is as follows:

forget about the books_model class completely; bin it.

In the 'new' controller:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Books extends Controller
{
    function __construct() {
            
        parent::Controller();
        $this->load->helper('url');
        $this->load->database();
        $this->load->library('pagination');
    }


    function index() {
        
        $data['title'] = 'Books Entries Listing';        
        $data['result'] = $this->db->get('books','5', $this->uri->segment(3));
                                //produces SELECT * FROM books LIMIT offset, num rows to return    
                                // SELECT * FROM books LIMIT $this->uri->segment(3), 3

        //set pagination parameters
        $config['base_url'] = 'http://localhost/CIgniter/books/index/';
        $config['total_rows'] = $this->db->count_all('books');            //returns 17
        $config['per_page'] = '5';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);

        // create pagination links
        $data['links'] = $this->pagination->create_links();
        
        //load the view
        $this->load->view('books_view', $data);
    }

}


/* End of file books.php */
/* Location: ./system/application/controllers/books.php */


and in the 'new' books_view file:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;link rel="stylesheet" href='&lt;?php echo base_url(); ?&gt;css/main.css' type="text/css" media="screen, projection" /&gt;
&lt;title&gt;CodeIgniter Pagination Tutorial&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>Book search</h1>
<table>
&lt;?php foreach($result->result_array() as $book): ?&gt;

<tr><td>&lt;?php echo $book['bookID'];?&gt;</td><td>&lt;?php echo $book['aid'] ?&gt;</td><td>&lt;?php echo $book['title']?&gt;</td><td>&lt;?php echo $book['company']?&gt;</td><td>&lt;?php echo $book['typedesc']?&gt;</td><td>&lt;?php echo $book['isbn']; ?&gt;</td>

&lt;?php endforeach; ?&gt;
</table>
<p>&lt;?php echo $links; ?&gt;</p>
&lt;/body&gt;
&lt;/html&gt;

It takes away the model->view->controller aspect turning the script into controller->view; which is a little disapointing, but hey, it works a charm over here!

The offset clause in the MySQL query takes a bit of getting used to (fiddling with)!


hope this helps

best wishes :-)


Messages In This Thread
Pagination, offset issue - by El Forum - 01-12-2010, 04:48 AM
Pagination, offset issue - by El Forum - 01-13-2010, 08:16 AM
Pagination, offset issue - by El Forum - 01-13-2010, 11:15 AM
Pagination, offset issue - by El Forum - 01-13-2010, 04:09 PM
Pagination, offset issue - by El Forum - 01-13-2010, 07:15 PM
Pagination, offset issue - by El Forum - 01-14-2010, 03:09 AM
Pagination, offset issue - by El Forum - 01-14-2010, 04:47 AM
Pagination, offset issue - by El Forum - 01-14-2010, 05:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB