Recently i've rewritten my code to PDO from mysql query. Insert, fetch, update, delete everything working fine. But, pagination not displaying in my page. Before i've used mysql query. In that time pagination worked perfectly. Now, i've changed my codes into prepared statements. pagination not dispalying i don't know what should i do? Below i've posted my coding (pagination only)...
<?php
include('config.php');
include('paginate.php');
$per_page = 10;
try
{
//some codes
}
catch(PDOException $e)
{
//some codes
}
$total_results = $stmt->fetchColumn();
$total_pages = ceil($total_results / $per_page);
if (isset($_GET['page'])) {
$show_page = $_GET['page'];
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
}
else {
$start = 0;
$end = $per_page;
}
} else {
$start = 0;
$end = $per_page;
}
$page = intval($_GET['page']);
$tpages=$total_pages;
if ($page <= 0)
$page = 1;
?>
<html>
<head>
<title></title>
</head>
<body>
<table width="1200" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td height="8" colspan="6" > </td>
</tr>
<tr>
<td colspan="6">
</td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td height="35" colspan="12" align="center" valign="middle">
<div class="headdiv"> LISTS </div>
</td>
</tr>
<tr>
<td>
<?php
try
{
//some codes
}
catch(PDOException $e)
{
//some codes
}
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
echo '<div style="margin-left:60px;" class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
}
echo "</ul></div>";
?>
</td>
<td>
<table align="center" width="310" height="40" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="270" align="right" style="background: rgba(200,200,200, .2); padding:2px 10px 2px 0px; border-top-left-radius: 5px; border-bottom-left-radius: 5px;">
<?php
//some codes
?>
</td>
<td width="40" style="background: rgba(200,200,200, .2); padding:2px 0px 2px 0px; border-top-right-radius: 5px; border-bottom-right-radius: 5px;">
<?php
//some codes
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="12">
<?php
echo "
//some codes
";
for($i = $start; $i < $end; $i++)
{
if ($i == $total_results)
{
break;
}
while($row = $stmt->fetch())
{
//some codes
}
}
echo "</table>";
?>
</td>
</tr>
<tr>
<td colspan="2">
<?php
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
echo '<div style="margin-left:60px;" class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
}
echo "</ul></div>";
?>
</td>
</tr>
</table>
</body>
</html>