Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,415
    Thanks
    269
    Thanked 32 Times in 31 Posts

    pagination issue

    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.

    PHP Code:

    $record_per_page
    =6;

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

    $tendayzdate('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();
    //$result=$db->get_results($rs.$limit);

    $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 && $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

    PHP Code:
    $i=0;
            //while ($indx < $resultvid) {
              while($sql_array=mysql_fetch_array($rs)){              
             
               
                //$indx++;
                  
                           //$sql_array = shuffle($aVideos);
                           $sql_array = array_shift($aVideos); //shuffle not used here on this file.
                      

                    $vid_private="";

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

                    $vid_info = $sql_array->getInfo('small');
                    
    if($sql_array->approved=='0'){$image="$CONST_IMAGE_ROOT/latest_videos_pend.jpg";}
    if($sql_array->approved=='1'){$image="$CONST_IMAGE_ROOT/latest_videos.jpg";}
    if($sql_array->approved=='0'){$vid_status="Pending Approval";}
    if($sql_array->approved=='1'){$vid_status="Approved";}
                
    // print 3 vids per row on page
    if(($i%3)==0)
        {
        print "</td></tr><tr><td colspan='0'>&nbsp;</td></tr>
        <tr>";
    }

    ?>

     <div>

    //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

    </div>

    <?php
                    
      $i
    ++;
          }

    $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)
    Last edited by durangod; 11-23-2011 at 11:24 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I usually use the LIMIT parameter in the query.
    And I save two values in a PHP SESSION, the start page and how many.

    http://php.about.com/od/mysqlcommands/g/Limit_sql.htm

    $start_page=10;
    $how_many=5;

    $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.

    .

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,415
    Thanks
    269
    Thanked 32 Times in 31 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •