Hi
I have created a new wordpress template page that reads in the results from my custom table (5 at a time).
I have done something wrong as I am getting the correct # of pages as href’s at bottom of page (3 page links), but when I click these page #'s, I get the same results on each page (the first 5 records).
My variable $this_page_first_result just isn’t working right.
Much appreciated if someone could review and let me know what I have done wrong.
Thanks.
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php
global $wpdb;
$iResultsPerPage = 5;
$sSql = "SELECT * FROM fruit";
$iRows = $wpdb->get_results($sSql);
$iTotalRows = $wpdb->num_rows;
$iNumPages = ceil($iTotalRows / $iResultsPerPage);
if (! isset($_SESSION['page']))
{
$_SESSION["page"] = "1";
$page = $_SESSION["page"];
}
else
{
$page = $_SESSION["page"];
}
$this_page_first_result = ($page-1) * $iResultsPerPage;
$sSql = "SELECT * FROM fruit LIMIT " . $this_page_first_result . "," . $iResultsPerPage;
$iRows = $wpdb->get_results($sSql);
$iTotalRows = $wpdb->num_rows;
foreach ($iRows as $row)
{
echo "$row->fruit_id ";
echo "$row->name ";
echo "$row->variety<br/>";
}
echo "<br><br>";
for ($page = 1; $page <= $iNumPages; $page++)
{
echo '<a href="http://localhost/mysite/test-pagination?page=' . $page . '">' . $page . '</a> ';
}
?>
<br /><br />
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>