Results 1 to 1 of 1

Thread: [RESOLVED] Pagination Issues

  1. #1
    Join Date
    Nov 2010

    resolved [RESOLVED] Pagination Issues


    If you click on the link to my page and then click the site admin and have it drop down, click on templates and there you will see its contents load in the right content div. It says I currently have 4 templates stored in my database. Which is correct. My problem lies with my pagination code. If I assign the display variable any number more than the amount of templates in the database it will still display that number of templates in my database where it says "You have <?php if($rows == 0){echo '0';}else{echo $rows;} ?> templates.", however with my pagination code lets say I put 2 for the display variable, which means it would have 2 pages with 2 templates displayed on each page. The issue is when I do that it then displays how many templates is on that page instead of how many is in the database and not sure why.

    One last thing is if you notice the listing of the pages its all messed up. Obviously it should be displayed differently. Also with the current page should have a class of active attached to it.

    Any help to fix any of these issues would be great. Thank you.

    PHP Code:
    // Include the database page
    include ('../inc/dbconfig.php');
    // Number of records to show per page
    $display 2;
        if (isset(
    $_GET['p']) && is_numeric($_GET['p'])) {
    $pages $_GET['p'];
        } else { 
    // Need to determine
            // Count the number of records
    $q "SELECT COUNT(id) FROM templates";
    $r mysqli_query($dbc$q);
    $row mysqli_fetch_array($rMYSQLI_NUM);
    $records $row[0];
    // Calculate the number of pages...
    if ($records $display) { // More than 1 page.
    $pages ceil($records/$display);
            } else {
    $pages 1;
    // End of p IF.
        // Determine where in the database to start returning results...
    if (isset($_GET['s']) && is_numeric($_GET['s'])) {
    $start $_GET['s'];
        } else {
    $start 0;
    // End of s IF.
    $query "SELECT CONCAT_WS(' ', firstname, lastname) AS name, DATE_FORMAT(templates.datecreated, '%M %d, %Y') AS datecreated, templatename FROM templates, handlers WHERE handlers.id = templates.creator_id LIMIT $start$display";
    $result mysqli_query $dbc$query ); // Run The Query
    $rows mysqli_num_rows($result);

    <!-- Title -->
                <div id="title" class="b2">
                    <!-- TitleActions -->
                    <div id="titleActions">
                        <!-- ListSearch -->
                        <div class="listSearch actionBlock">
                            <div class="search">
                                <label for="search">Recherche</label>
                                <input type="text" name="search" id="search" class="text" />
                            <div class="submit">
                                <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button>
                        <!-- /ListSearch -->
                        <!-- newPost -->
                            <div class="newPost actionBlock">
                                <a href="#" class="button"><strong>New post<img src="img/icons/add_48.png" alt="new post" class="icon "/></strong></a>
                        <!-- /newPost -->
                    <!-- /TitleActions -->
                <!-- Title -->

                <!-- Inner Content -->
                <div id="innerContent">

                    <!-- ListHeader -->
                    <div id="listHeader">
                        <p class="listInfos">
                            You have <?php if($rows == 0){echo '0';}else{echo $rows;} ?> templates.
                        <div class="listActions">
                            <form action="" method="post">
                                <label for="actionSelect">With selected items: </label>
                                <select class="select" name="actionSelect" id="actionSelect">
                                <button class="button small-button"><strong>Apply</strong></button>
                    <!-- /ListHeader -->
    if ($rows 0) {
                    <!-- ListTable -->
                    <table cellspacing="0" class="listTable" id="postList">
                        <!-- Thead -->
                                <th class="first"><div></div></th>
                                <th><a href="#" title="Template Name">Template Name</a></th>
                                <th><a href="#" title="Creator">Creator</a></th>
                                <th class="last"><a href="#" title="Date Created">Date Created</a></th>
                        <!-- /Thead -->
                        <!-- Tfoot -->
                                <td colspan="5">
                                    <div class="inner">
                                        <div class="paginate">
    if ($pages 1) {
    // Determine what page the script is on:
    $current_page = ($start/$display) + 1;
    // If its not the first page, make a Previous button
    if ($current_page != 1) {
    '<span class="prev disabled"><a href="templates.php?s=' . ($start $display) . '$p=' $pages '">&lt;&lt;</a></span>';
    // Make all the numbered pages:
    for ($i 1$i <= $pages$i++) {
                                                        if (
    $i != $current_page) {
    '<span class="current roundedBordersLite"><a href="templates.php?s=' . (($display * ($i 1))). '$p=' $pages '">' $i '</a></span>';
                                                        } else {
    $i ' ';
    // End of FOR Loop.
                                                    // If its not the last page, make a Next button:
    if ($current_page != $pages) {
    '<span class="next"><a href="#">&gt;&gt;</a></span>';
    // End of links pages.
                        <!-- /Tfoot -->
                        <!-- Tbody -->
    while ( $row mysqli_fetch_array $resultMYSQL_ASSOC ) ) {
                              <td><input type=checkbox class=checkbox /></td>
    $row['templatename'] . '</td>
    $row['name'] . '</td>
                              <td class=last>' 
    $row['datecreated'] . '</td>
                        <!-- /Tbody -->
                    <!-- /ListTable -->

                <!-- /Inner Content -->
    Last edited by xtremer360; 11-23-2010 at 05:53 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center