Jump to content

Results from Infinite Scroll


genista

Recommended Posts

Hi,

I have an infinite scroll scipt that is pulling data and displaying it just fine. However, I am finding that when you scroll down the data pull starts again at the beginning. Right now I have 8 rows for testing in the database to make it easy. My control to get the next data set does not seem to be working otherwise it would go to the next set of results?

PHP Code:

 

//item per page  

    $limit 5;   
    
$page =(int)(!isset($_GET['p']))?1$_GET['p'];  
   
    
// sql query  
    
$sqlContent="SELECT make, model, year, carid FROM cars";  
      
    
//Query start point  
    
$start =($page $limit)- $limit;  
   
    
$resContent=$DB_con->query($sqlContent);  
        
$rows_returned$resContent->rowCount();//->fetchColumn();  
       
    // query for page navigation  
    
if( $rows_returned > ($page $limit)){  
        
$next =++$page;  
                
    }  
          

    
$sqlContent $sqlContent ." LIMIT $start$limit";  
    
$finalContent $DB_con->query($sqlContent);  
    if(
$finalContent === false) {  
        
trigger_error('Error: ' $DB_con->errorE_USER_ERROR);  
    } else {  
      
            
$rows_returned$finalContent->rowCount();//->fetchColumn();  
    
}  
?>  

then display the results:

PHP Code:


PHP Code:
 <?php while($rowContent $finalContent->fetch()) {  
    
$year $rowContent['year'];  
    
$make $rowContent['make'];  
    
$model $rowContent['model'];  
    
?>  
    <div class="row">  
      <div class="ride"><?php echo "$year $make $model"?></div>  
      </div>  
    <?php ?>  
   </div>  
      </div>  
    <!--page navigation-->  
    <?php if(isset($next)):?>  
        <div class="nav">  
            <a href='index.php?p=<?php echo $next?>'>Next</a>  
        </div>  
    <?php endif ?>  
    </div>

When I print some of the variables, this is what I get:

 

start=0
rows_returned = 5
next=2
page=2

Page 2 starts from the beginning, shouldn't that be 1 and then increment?

 

Thanks,

G

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.