Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page numbers won't show with pagination->render #33

Closed
gigaboy opened this issue Aug 3, 2021 · 5 comments
Closed

Page numbers won't show with pagination->render #33

gigaboy opened this issue Aug 3, 2021 · 5 comments

Comments

@gigaboy
Copy link

gigaboy commented Aug 3, 2021

Using mysql example, about 600 records, 25 records per page. Using BS5. Latest version downloaded today. Displays forward and back arrows correctly, but no numbers in between. Can move between pages using the arrows. Data records display correctly.

  // connect to a database
  require_once "config.php";

  // how many records should be displayed on a page?
  $records_per_page = 25;

  // include the pagination class
  require 'custom/pagination/Zebra_Pagination.php';

  // instantiate the pagination object
  $pagination = new Zebra_Pagination(); 

  // set position of the next/previous page links
  $pagination->navigation_position(isset($_GET['navigation_position']) && in_array($_GET['navigation_position'], array('left', 'right')) ? $_GET['navigation_position'] : 'outside');

  // if we have to show condensed links
  if (isset($_GET['condensed']) && ($_GET['condensed'] == 1 || $_GET['condensed'] == 2)) $pagination->condensed($_GET['condensed'] == 2 ? true : '');

  // Get the records just for this page
  $sql = '
      SELECT book_id, book_title, book_subtitle, book_author_first_name, book_author_last_name, datestamp 
      FROM books 
      ORDER BY datestamp DESC
      LIMIT 
          ' . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
  ';

  // execute the MySQL query
  // (you will use mysqli or PDO here, but you get the idea)
  $result = mysqli_query($link, $sql) or die(mysqli_error($link));

  // fetch the total number of records in the table
  $rows = mysqli_fetch_assoc(mysqli_query($link, 'SELECT COUNT(*) AS rows FROM books'));

  // pass the total number of records to the pagination class
  $pagination->records($rows['rows']);

  // records per page
  $pagination->records_per_page($records_per_page);

?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="generator" content="">
    <title></title>

    <link rel="canonical" href="">
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="custom/style.css" rel="stylesheet">
    <link rel="stylesheet" href="custom/pagination/zebra_pagination.css" rel="stylesheet">
    
    <style type="text/css">
        .wrapper{
            width: 650px;
            margin: 0 auto;
        }
        .page-header h2{
            margin-top: 0;
        }
        table tr td:last-child a{
            margin-right: 5px;
        }
    </style>

</head>
<body class="bg-light">
    
  <main>

    <div class="py-5 text-center">
        <h3>GOL Record List</h3>
        <a href="dashboard.php"><button type="button" class="btn btn-outline-primary">Return to Dashboard</button></a>
    </div>

    <div class="mx-auto" style="width: 1024px;">
      
      <table class="table table-striped table-hover table-bordered table-sm">
        <thead class="table-info">
          <tr>
            <th>&nbsp;</th>
            <th>Author</th>
            <th>Title</th>
            <th>Date</th>
          </tr>
        </thead>

        <tbody>
          <?php $index = 0; while ($row = mysqli_fetch_assoc($result)): ?>
            <tr<?php echo $index++ % 2 ? ' class="even"' : ''; ?>>
                <td><a type="button" class="btn btn-secondary btn-sm" href="<?php //echo $row['book_id']; ?>">Edit</a></td>
                <td class="text-left"><?php echo $row['book_author_first_name']; ?>&nbsp;<?php echo $row['book_author_last_name']; ?></td>
                <td><?php echo $row['book_title']; ?>&nbsp;<?php echo $row['book_subtitle']; ?></td>
                <td><?php echo $row['datestamp']; ?></td>
            </tr>
          <?php endwhile; ?>
        </tbody>

      </table>

      <?php $pagination->render(); ?>

    </div>

  </main>

  <script src="bootstrap/js/popper.min.js"></script>      
  <script src="bootstrap/js/bootstrap.min.js"></script>
@gigaboy
Copy link
Author

gigaboy commented Aug 3, 2021

2021-08-02_21-03-21

@stefangabos
Copy link
Owner

did you manage to find the issue for this?
if not i can now look into it if it's still of interest

@gigaboy
Copy link
Author

gigaboy commented Sep 6, 2021 via email

@stefangabos
Copy link
Owner

stefangabos commented Sep 7, 2021

You have your error reporting set to off.
In development you should always have

ini_set('display_errors', 1);
error_reporting(E_ALL);

...in order to catch errors.

With error reporting on, where you do

$rows = mysqli_fetch_assoc(mysqli_query($link, 'SELECT COUNT(*) AS rows FROM books'));

you would get the the following error

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in

While the error doesn't really tell you everything, it tells you that instead of a result set it returned a boolean value - which means it failed. And it failed because rows is a reserved word and you have to use ticks around it like so

$rows = mysqli_fetch_assoc(mysqli_query($link, 'SELECT COUNT(*) AS `rows` FROM books'));

@gigaboy
Copy link
Author

gigaboy commented Sep 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants