pagination error - help |
[eluser]oliur[/eluser]
Can anyone tell me how this $this->uri->segment() is supposed to work in pagination. I am getting this error message: Quote: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 controller : Code: class Site extends Controller{ Model: Code: class post_model extends Model{ View: Code: <?php
[eluser]Krzemo[/eluser]
Seems like you $offset is empty. If there is nothing in $this->uri->segment(3) it shuld return FALSE. I'm wondering if there is coercion to int 1 in this case. Are you using any routings in your app?
[eluser]oliur[/eluser]
not that I am aware of. But when you say routing what do you exactly mean? Sorry, I am still new to CI. Is there something I need to check on the config settings? I am not sure how do you pass offset in the first page? Does the system automatically reads it from the url ? Is there anyway someone can let me know if the above code works fine in their system. Just wondering if it is my configuration that is returning an empty uri segment.
[eluser]Krzemo[/eluser]
show the page url is it like http://site.com/controller/function/pagenumber ?
[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 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){ ANOTHER SOLUTION : I was going wrong in not checking for null values for the offset parameter. Code: function getPost($perPage,$offset = 0){ |
Welcome Guest, Not a member yet? Register Sign In |