Xtremer360 Posted July 1, 2011 Share Posted July 1, 2011 I'm not sure why but for some reason its still showing both records from the db. I thought with how I have it set up it should be showing 1 on the first page and 1 on the second page because the number of returned results from the query is 2. <?php require("../inc/dbconfig.php"); require("../inc/global_functions.php"); require("../inc/variables.php"); $query = "SELECT CONCAT_WS(' ',firstName,lastName) AS name, username, emailAddress, id FROM manager_users"; $result = mysqli_query($dbc,$query); $rows = mysqli_num_rows($result); $itemsPerPage = 1; $pages = ceil($rows/$itemsPerPage); $fileName = basename($_SERVER[php_SELF]); ?> <script type="text/javascript"> $(document).ready(function() { $('#usersPageList').tablesorter().tablesorterPager({container:$('#usersPageList .pagination'),cssPageLinks:'a.pageLink'}); $('a.bt_green').click(function(e) { e.preventDefault(); $('div.right_content').load('forms/addnew/' + $(this).attr('id')); }); }); </script> <h2>User Accounts</h2> <table id="usersPageList" class="rounded-corner"> <thead> <tr> <th scope="col" class="rounded-first"></th> <th scope="col" class="rounded">Name</th> <th scope="col" class="rounded">Email Address</th> <th scope="col" class="rounded">Username</th> <th scope="col" class="rounded">Edit</th> <th scope="col" class="rounded-last">Delete</th> </tr> </thead> <tfoot> <tr> <td colspan="5" class="rounded-foot-left"><em>Displays all of the registered and verified users!</em></td> <td class="rounded-foot-right"> </td> </tr> </tfoot> <tbody> <?php if ($rows > 0) { while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td><input type=\"checkbox\" name=\"\" /></td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['emailAddress']."</td>"; echo "<td>".$row['username']."</td>"; echo "<td><a href=\"#\"><img src=\"images/user_edit.png\" alt=\"\" title=\"\" border=\"0\" /></a></td>"; echo "<td><a href=\"#\" class=\"ask\"><img src=\"images/trash.png\" alt=\"\" title=\"\" border=\"0\" /></a></td>"; echo "</tr>"; } } else { echo "<td>There are currently no users found in the database!"; } ?> </tbody> </table> <?php addRemove($fileName); pagination($pages); ?> Quote Link to comment https://forums.phpfreaks.com/topic/240894-not-putting-correct-number-for-each-page/ Share on other sites More sharing options...
wildteen88 Posted July 1, 2011 Share Posted July 1, 2011 We need to see the code for your pagination() function, I presume this is the function you're using for generating your page links. Quote Link to comment https://forums.phpfreaks.com/topic/240894-not-putting-correct-number-for-each-page/#findComment-1237380 Share on other sites More sharing options...
Xtremer360 Posted July 1, 2011 Author Share Posted July 1, 2011 Thank you for your response. I would like to mention I am also using jQuery's tablesorter.pager script to assist with this but my function is as follows: <?php function pagination($pages) { echo "<div class=\"pagination\">"; if ($pages == 1) { } else { for ($i = 1; $i <= $pages; $i++) { echo "<span class=\"\"><a href=\"#\" class=\"pageLink\">".$i."</a></span>"; } } echo "</div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240894-not-putting-correct-number-for-each-page/#findComment-1237382 Share on other sites More sharing options...
wildteen88 Posted July 1, 2011 Share Posted July 1, 2011 You're not setting up the pagination properly. The following tutorial will show you how to setup pagination properly http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/240894-not-putting-correct-number-for-each-page/#findComment-1237384 Share on other sites More sharing options...
Xtremer360 Posted July 2, 2011 Author Share Posted July 2, 2011 I guess I should ask now is will it still work with the jquery pager plugin i use. Quote Link to comment https://forums.phpfreaks.com/topic/240894-not-putting-correct-number-for-each-page/#findComment-1237687 Share on other sites More sharing options...
monkeytooth Posted July 2, 2011 Share Posted July 2, 2011 problem one to your pagination is your querying all results.. you should LIMIT the query and have the LIMIT be set dynamicly through variables.. so it can pull sets of records that would match the page.. say you wanna show $x per page.. 10 for example you have a variable there.. then for your page LIMIT variables you should have a divisible number of 10.. so 1,10 would be your fist limit on page one.. so it will pull records 1-9 off the top of the db, then page 2 would be 11,20.. and so on.. it involves math.. I know you hate math lol.. Also cause you might not always pull 10 results you need to have your loops break should there be less than 10.. Quote Link to comment https://forums.phpfreaks.com/topic/240894-not-putting-correct-number-for-each-page/#findComment-1237692 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.