Welcome Guest, Not a member yet? Register   Sign In
pagination error - help
#5

[eluser]oliur[/eluser]
First link : http://localhost/kikorben/site/index

2nd link : http://localhost/kikorben/site/index/10

What I can see from the url is that the offset number is missing at the end in the first link and I think there is nothing wrong with that if you do a little modification in your model class

modified code:
Code:
function getPost($perpage,$offset = 0)

This should ensure the first page starts with an offset of 0 by default.

The pagination is working now, as in all of my links are working fine except the first link. I still get that empty offset error message in the SQL for the first link.


Quote:A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10' at line 1

SELECT * FROM `orders` LIMIT ,10


I've also changed this line of code in my controller:

Code:
$page_details['post_rows'] = $this->post_model->getPost($config['per_page'], $this->uri->segment(3));


EDITED: THIS HAS SOLVED MY PROBLEM

Code:
function getPost($perPage,$offset = 0){
        
        /*
        $sql = "SELECT * FROM `orders` LIMIT $perPage,$offset";
        $q = $this->db->query($sql);
        */
        $this->db->limit($perPage, $offset);
        $q = $this->db->get('orders');
            
        return $q->result();
    }

ANOTHER SOLUTION : I was going wrong in not checking for null values for the offset parameter.

Code:
function getPost($perPage,$offset = 0){

if($offset != '') $offset = $offset;
else $offset = 0;
$sql = "SELECT * FROM `orders` LIMIT $offset,$perPage";
$q = $this->db->query($sql);
return $q->result();
}


Messages In This Thread
pagination error - help - by El Forum - 12-17-2009, 04:04 PM
pagination error - help - by El Forum - 12-17-2009, 05:22 PM
pagination error - help - by El Forum - 12-17-2009, 05:36 PM
pagination error - help - by El Forum - 12-17-2009, 06:31 PM
pagination error - help - by El Forum - 12-18-2009, 03:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB