Jump to content

Not putting correct number for each page.


Xtremer360

Recommended Posts

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);
?>

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>";
}
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.