Conf1 Posted June 29, 2015 Share Posted June 29, 2015 So this is my code for pagination <?php $num_rec_per_page=8; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $sql="SELECT * FROM `images` ORDER BY `id` DESC LIMIT $start_from,$num_rec_per_page"; $rdata=mysqli_query($mysqli, $sql); while($res=mysqli_fetch_array($rdata)) { $imgname=$res['image']; $path = 'folder/'.$imgname; echo " <div class='col-xs-6 col-md-3'> <a href='#'' class='thumbnail'> <img src='$path' height='500' width='500'> </a> </div>"; } $total_records = mysqli_num_rows($rdata); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); for ($i=1; $i<=$total_pages; $i++) { }; ?> <br><br> <footer> <br><br> <div class="well text-center"> a href="<?php echo "index.php?page=1"; ?>"><button type="button" class="btn btn-fresh text-uppercase">Previous page</button></a> <a href="<?php echo "index.php?page=".$i." "; ?>"><button type="button" class="btn btn-sky text-uppercase">Next page</button></a> </div> Now when I press "Next page" button, I can go to only 2 page, not more, but there must be more pages because there is more posts.. Quote Link to comment https://forums.phpfreaks.com/topic/297102-page-pagination-problem/ Share on other sites More sharing options...
fastsol Posted June 29, 2015 Share Posted June 29, 2015 You're not incrementing $i anywhere. You have a for() but you don't have any code in it to build the links properly. Check out the first link in my signature and got to the code snippets tab, you'll find something helpful there. Quote Link to comment https://forums.phpfreaks.com/topic/297102-page-pagination-problem/#findComment-1515222 Share on other sites More sharing options...
cyberRobot Posted June 30, 2015 Share Posted June 30, 2015 In addition to what fastsol said, the following line is only going to give you the number of records retrieved from your query: $total_records = mysqli_num_rows($rdata); //count number of records Since the query uses the LIMIT clause, $total_records is never going to be more than 8. To set $total_records, you could create a separate query that counts all the records in the "images" table. Quote Link to comment https://forums.phpfreaks.com/topic/297102-page-pagination-problem/#findComment-1515280 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.