View Full Version : pagination issue

11-24-2011, 12:11 AM
The issue is that my pagination works fine page wize but for some reason the array is jumping back to the first three elements on page 2

Here is the set up - i have 9 videos
page one shows vids 0-5 (6 vids per page)
page two however goes back to show vids 0-2 instead of 6-8

so for some reason on new page load its not incrementing the pointer to the next record its just resetting as if it was page one. And i dont get what im missing here in process.

i dont think the issue is with the pag_links() function is it works fine in other files and is a carbon copy of those, so i think we can rule that out as it works just fine elsewhere.

Top of page query and var set up.


$lastten = time() - (5000 * 24 * 60 * 60);
//i changed this to 5000 for testing only
// 30 days; 24 hours; 60 mins; 60secs

$tendayz= date('Y-m-d', $lastten);
// or using strtotime():
//echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";

$query="SELECT * FROM videos WHERE vid_time >= '$tendayz' AND vid_private='N' AND vid_userid > '0' ORDER BY vid_time DESC";

$pager = new PS_Pagination($link,$query,$record_per_page,6);
$rs = $pager->paginate();

$aVideos = $video->GetListByDate($tendayz);
$resultvid = count($aVideos);

// then i set vars for pagination display and process

$maxpg = $pager->max_pages;
$curpg = $pager->page;
$rppg = $pager->rows_per_page;
$off_setpg = $pager->offset;

function pag_links() {
global $curpg, $maxpg;

/****** build the pagination links ******/
// range of num links to show on either side of current page
$range = 5;

//echo "<span class=\"pagebar\">";

// show $range pages on either side of current page. if this includes page
// 1, don't show "First". if this includes last page, don't show "Last"
// show back links |< and < unless at page 1
if ($curpg > 1) {
if ($curpg - $range > 1) { // wouldn't show page 1 in range
// show << link to go back to page 1
echo "<a href='{$_SERVER['PHP_SELF']}?page=1'>|&lsaquo;</a> ";
// get previous page num
$prevpage = $curpg - 1;
// show < link to go back 1 page
echo "<a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>&lsaquo;</a> ";

// loop to show links to range of pages around current page
// if previous page <, there is a space after it

for ($x = $curpg - $range;
$x < $curpg + $range + 1;
$x++) {
// if it's a valid page number (not < 1 or > last page)...
if ($x > 0 && $x <= $maxpg) {
// if we're on current page, not a link...
if ($x == $curpg) {
// 'highlight' it but don't make a link
echo "[<b>$x</b>] ";
} else {
// if not current page, make it a link
echo "<a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> ";

// if not on last page, show forward > and last page >| links
if ($curpg < $maxpg) {
// get next page
$nextpage = $curpg + 1;
// echo forward link for next page
echo "<a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>&rsaquo;</a> ";
// echo forward link for lastpage, unless last page already showing
if ($curpg + $range < $maxpg) {
echo " <a href='{$_SERVER['PHP_SELF']}?page=$maxpg'>&rsaquo;|</a>";

//echo "</span>";
/****** end build pagination links ******/
} // end pag_links()

Now for the pricess part of it

//while ($indx < $resultvid) {


//$sql_array = shuffle($aVideos);
$sql_array = array_shift($aVideos); //shuffle not used here on this file.


if($sql_array->vid_private=='Y') $vid_private="checked";

$vid_info = $sql_array->getInfo('small');

if($sql_array->approved=='0'){$vid_status="Pending Approval";}

// print 3 vids per row on page
print "</td></tr><tr><td colspan='0'>&nbsp;</td></tr>



//here is where i do the object for the video which displays fine, rows are all good and formated correct it just wont go the next element in array on page 2




$rs is a single record of the array(current video),
$avideos is all the elements (all the videos in the query result - so all 9 video elements) and
$resultvid = 9 (correct)

11-24-2011, 05:31 AM
I usually use the LIMIT parameter in the query.
And I save two values in a PHP SESSION, the start page and how many.



$query="SELECT * FROM videos WHERE vid_tim
e >= '$tendayz' AND vid_private='N' AND vid_userid > '0' ORDER BY vid_time DESC LIMIT $start_page, $how_many";

Remember your query array starts at zero (0),
so in that example, your result would be pages 9,10,11,12,13

And then more logic to stop at the last page, or wrap around.


11-24-2011, 09:18 PM
Yeah added the limit and other and still doing the same or not showing at all. So what ill have to do is take out the embed temporarily and just do a print_r on the array per page and see if i can isolate and break down how exactly the array is being read and displayed.

Thanks for the help, i will work on this today and see what i can find. The strange thing is if i think about this in a very simplified way, its the exact same principle as with my member profile and member display pages which work perfect. They follow the exact same process almost line for line. The only difference is that one is image and profile data and this is video display array. So the principle is the same and the structure is the same, the difference is the array is different data.

So it should work, but ill dig into it later and see what i can find.

Appreciate the help.