genista Posted September 11, 2015 Share Posted September 11, 2015 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->error, E_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=0rows_returned = 5next=2page=2Page 2 starts from the beginning, shouldn't that be 1 and then increment? Thanks,G Quote Link to comment Share on other sites More sharing options...
Barand Posted September 11, 2015 Share Posted September 11, 2015 $next =++$page; increments $page then assigns that value to $next, so if $page was 1 it get incremented to 2 then that is assigned to next Quote Link to comment Share on other sites More sharing options...
genista Posted September 11, 2015 Author Share Posted September 11, 2015 Thanks, so if that is not the issue, what is causing the results to start again once the user gets to the end? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 11, 2015 Share Posted September 11, 2015 What is in $_GET['p'] at that point. That is what determines which records are displayed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.