stefangabos / Zebra_Pagination

A generic, Twitter Bootstrap compatible, pagination library for automatically generating navigation links

Home Page:https://stefangabos.github.io/Zebra_Pagination/Zebra_Pagination/Zebra_Pagination.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result

Mianovag opened this issue · comments

commented

hi there, i cant fix this problem, i have no clue how to manage this error.
this is the error on final end
Anotación 2020-03-06 172733

so far the code is ok according with the example

// database connection details
$MySQL_host = 'localhost';
$MySQL_username = 'root';
$MySQL_password = 'pass';
$MySQL_database = 'mydatabase';

// if could not connect to database
if (!($connection = @mysqli_connect($MySQL_host, $MySQL_username, $MySQL_password, $MySQL_database)))

    // stop execution and display error message
    die('Error connecting to the database!<br>Make sure you have specified correct values for host, username, password and database.');

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

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

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

// if we want to show records in reversed order
if (isset($_GET['reversed'])) {

    // show records in reversed order
    $pagination->reverse(true);

    // when showing records in reversed order, we need to call the "records" and "records_per_page" method
    // before calling the "get_page" method

    $result = mysqli_query($connection, 'SELECT COUNT(id) AS records FROM id') or die (mysqli_error($connection));
    $total = mysqli_fetch_assoc($result);

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

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

}

// 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');

// the MySQL statement to fetch the rows
$MySQL = '
    SELECT
        id, title, status
    FROM
        gn_blog
    ORDER BY
        a_date
    LIMIT
        ' . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
';

// if query could not be executed
if (!($result = @mysqli_query($connection, $MySQL)))

    // stop execution and display error message
    die(mysqli_error($connection));

// fetch the total number of records in the table

//
// HERE IS THE LINE THAT SHOWS THE ERROR
$rows = mysqli_fetch_assoc(mysqli_query($connection, 'SELECT COUNT(
) AS rows FROM gn_blog'));
/
*/

// if we are not showing records in reversed order
// (if we are, we already set these)
if (!isset($_GET['reversed'])) {

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

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

}

?>

<table class="countries" border="1">
    <thead>
        <tr><th>Title</th></tr>
    </thead>
    <tbody>

    <?php $index = 0; while ($row = mysqli_fetch_assoc($result)): ?>
    <tr<?php echo $index++ % 2 ? ' class="even"' : ''; ?>>
        <td><?php echo $row['title']; ?></td>
    </tr>
    <?php endwhile; ?>

    </tbody>
</table>

<div class="text-center">

<?php

// render the pagination links
$pagination->render();

?>

as soon as you fix your mysql it will work
(remember, this class does not have anything to do with mysql - that's all you)

COUNT() expects an argument. try COUNT(*) or the name of a column