Hello,
The particular code I have in place is based off of search, that will then grab items from my data base and render the results in a table formatted display. pagination included.
}
$var1 = $_POST['var1'];
$query = "SELECT * FROM table WHERE state LIKE :search OR city LIKE :search";
$stmt = $dbh->prepare($query);
$stmt->bindValue(':search', '%' . $var1 . '%', PDO::PARAM_INT);
$stmt->execute();
$count = $stmt->rowCount();
$adjacents = 2;
$records_per_page = 5;
$page = (int) (isset($_POST['page_id']) ? $_POST['page_id'] : 1);
$page = ($page == 0 ? 1 : $page);
$start = ($page-1) * $records_per_page;
$next = $page + 1;
$prev = $page - 1;
$last_page = ceil($count/$records_per_page);
$second_last = $last_page - 1;
$pagination = "";
if($last_page > 1){
$pagination .= "<div class='pagination'>";
if($page > 1)
$pagination.= "<a href='javascript:void(0);' onClick='change_page(1);'>« First</a>";
else
$pagination.= "<span class='disabled'>« First</span>";
if ($page > 1)
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($prev).");'>« Previous </a>";
else
$pagination.= "<span class='disabled'>« Previous </span>";
if ($last_page < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $last_page; $counter++)
{
if ($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($counter).");'>$counter</a>";
}
}
elseif($last_page > 5 + ($adjacents * 2))
{
if($page < 1 + ($adjacents * 2))
{
for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($counter).");'>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($second_last).");'> $second_last</a>";
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($last_page).");'>$last_page</a>";
}
elseif($last_page - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href='javascript:void(0);' onClick='change_page(1);'>1</a>";
$pagination.= "<a href='javascript:void(0);' onClick='change_page(2);'>2</a>";
$pagination.= "...";
for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($counter).");'>$counter</a>";
}
$pagination.= "..";
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($second_last).");'>$second_last</a>";
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($last_page).");'>$last_page</a>";
}
else
{
$pagination.= "<a href='javascript:void(0);' onClick='change_page(1);'>1</a>";
$pagination.= "<a href='javascript:void(0);' onClick='change_page(2);'>2</a>";
$pagination.= "..";
for($counter = $last_page - (2 + ($adjacents * 2)); $counter <= $last_page; $counter++)
{
if($counter == $page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($counter).");'>$counter</a>";
}
}
}
if($page < $counter - 1)
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($next).");'>Next »</a>";
else
$pagination.= "<span class='disabled'>Next »</span>";
if($page < $last_page)
$pagination.= "<a href='javascript:void(0);' onClick='change_page(".($last_page).");'>Last »</a>";
else
$pagination.= "<span class='disabled'>Last »</span>";
$pagination.= "</div>";
}
$query = "SELECT * FROM table WHERE state LIKE :search OR city LIKE :search LIMIT $start, $records_per_page";
$stmt = $dbh->prepare($query);
$stmt->bindValue(':search', '%' . $var1 . '%', PDO::PARAM_INT);
$stmt->execute();
$count = $stmt->rowCount();
if($count > 0)
{
foreach($records as $row) {
$HTML.='<div>';
$HTML.= $row['State'];
$HTML.='</div><br/>';
}
}
else
{
$HTML='No Data Found';
}
echo $HTML;
echo $pagination;
?>
</body>
</html>
The issue is within the rendering itself. After the search is performed, the results are simply not displaying. However, the search is functionally performing what it needs to do because the pagination itself is corresponding. Is there an error within my code that is preventing the data from displaying? If so, what can i do to correct this? Thank you!