Welcome Guest, Not a member yet? Register   Sign In
Active Record "get()" with "limit()" and pagination/uri segment value displaying one too few results
#1

[eluser]fiddle-sticks[/eluser]
Hi please can somebody tell me why I am only getting a result of 11 items instead of 12 on the first page (no 3rd uri segment) with the following code.
Code:
$limit = 12;
$offset = $this->uri->segment(3, 0);
$this->db->order_by('created', 'desc');
$this->db->where('is_private !=', '1');
$row = $this->db->get('pictures', $limit, $offset);
Thanks in advance.
Ps Im not sure if posted this in the right place because I couldnt find exactly where this shoul be posted.
Regards
#2

[eluser]Dan Storm[/eluser]
Try using $this->db->last_query(); to verify that your SQL query is exactly as you expected. Additionally, try pasting the result from $this->db->last_query(); into phpMyAdmin and see if the results are as expected.
#3

[eluser]fiddle-sticks[/eluser]
yeah the query is fine - it ends in "LIMIT 12".
But still I am only getting 11 pictures being displayed in my view.
My view code goes roughly like this:
Code:
foreach($data->result() as $row):
if (@GETIMAGESIZE('template_images/' . $row->thumb_path)) {
echo "<div class='thumb_container'>";
$thumb_output = "<a >template_id . "' ><img src='" . $base_url  . '>thumb_path . "' /><div class='title_overlay'><strong>";
echo "</div>";
}
endforeach;
#4

[eluser]Dan Storm[/eluser]
[quote author="fiddle-sticks" date="1305564729"]yeah the query is fine - it ends in "LIMIT 12".
But still I am only getting 11 pictures being displayed in my view.
My view code goes roughly like this:
Code:
foreach($data->result() as $row):
if (@GETIMAGESIZE('template_images/' . $row->thumb_path)) {
echo "<div class='thumb_container'>";
$thumb_output = "<a >template_id . "' ><img src='" . $base_url  . '>thumb_path . "' /><div class='title_overlay'><strong>";
echo "</div>";
}
endforeach;
[/quote]

You probably get 12 rows returned but your if condition:
Code:
if (@GETIMAGESIZE('template_images/' . $row->thumb_path))
probably fails on one the first 12 rows and because of your encapsulation nothing gets outputted.
#5

[eluser]fiddle-sticks[/eluser]
But Ive got the same structure for two seperate views getting results from two seperate tables in the db. And the same error happens on both so Im guessing its a generic sort of problem with the code itself instead of the results. Im stumped
#6

[eluser]Dan Storm[/eluser]
The problem lies in your if condition. Try pulling it out of the foreach and just echo $row->thumb_path in your foreach loop and nothing else - you will see all twelve results.
#7

[eluser]fiddle-sticks[/eluser]
thanks I see what is wrong now. Some of the images were broken so the if statement would clean them out. pretty obvious in hindsight I suppose




Theme © iAndrew 2016 - Forum software by © MyBB