Welcome Guest, Not a member yet? Register   Sign In
MySQL problem?
#1

[eluser]carllawll[/eluser]
I'm trying to create a custom pagination type function, how ever there is only a button to get the next set of values. Although I've got it working, the first page returns 10 values as it should be on the second page (with 6 remaining entries) it only displays 5, which is some what strange. I'm almost certain my maths and query is right.

Could someone take a look for me?

Code:
$offset = ($page - 1) * $this->config->item('per_page');

However if I set it to this (despite giving me an error on the first page because you cant start from -1 Wink) it displays the remaining 6 entries

Code:
$offset = ($page - 1) * $this->config->item('per_page') -1;

For the sake of cutting down the size of my query I've removed the fields im retrieving

Code:
SELECT MYTABLEFIELDS FROM posts
INNER JOIN account ON posts.user_id = account.id
ORDER BY posts.date_added DESC
LIMIT $offset, $limit
#2

[eluser]CroNiX[/eluser]
Have you looked at CI's pagination library instead of doing your own?
#3

[eluser]carllawll[/eluser]
I have indeed, how ever from what I can see you can only suppress it to next and previous links, I have a single button that gets the next set of entries that I will also by linking up with jQuery so I'm not sure if the built in library is what I'm looking for

How ever please correct me if I'm wrong as it could potentially save me a bit of time!
#4

[eluser]CroNiX[/eluser]
You can try using the absolute value of your $offset, which would make the -1 a 1.
#5

[eluser]carllawll[/eluser]
I sorted it, there wasn't anything wrong with what I had but for some reason one of my entries must have had an error because it wasn't retrieving it, but after deleting it and putting some new entries in it works fine! Thanks for the help anyway Sr. R A




Theme © iAndrew 2016 - Forum software by © MyBB