I have a form that uses the method post. The form contains a submit button and on clicking it, my database records get displayed in an html table. I would like to limit the number of rows (5) displayed to each page, but I'm not looking to use GET. Is there any way I can do that with my post method?
// My form using post method
<form action = "" name = "dealer_call_log.php" id = "dealer_call_log.php" method = "post">
//Data displayed in the table below from post
$record_per_page = 5;
$page = '';
if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = 1;
}
$start_from = ($page - 1) * $record_per_page;
if(isset($_POST['submit'])){
echo '<center>';
echo '<br>';
$sql = "SELECT SFID, Comment, Time FROM tbl_call_log_detail
WHERE
(dealer_id = '$call_id' AND '$endDate'='1970-01-01' AND '$startDate' ='1970-01-01')
OR ( Time <= '$endDate' AND Time >= '$startDate'
AND (dealer_id = '$call_id' OR'$call_id'='' ))
OR ('$endDate'='1970-01-01' AND '$startDate' ='1970-01-01' AND '$call_id'='')
ORDER BY Time DESC LIMIT $start_from, $record_per_page" ;
$result = mysqli_query($conn, $sql);
$rows = mysqli_num_rows($result);
$all_property = array();
echo "<table class = 'data-table' border = '1' cellpadding = '9' bgcolor = '#CCCCCC'>
<tr class = 'data-heading'>";
while($property = mysqli_fetch_field($result)){
echo '<td><b> '. $property ->name. ' </b></td>';
array_push($all_property, $property ->name);
}
echo '</tr>';
}
while ($row = mysqli_fetch_array($result)){
echo '<tr>';
foreach($all_property as $item){
echo '<td> '. $row[$item] . ' </td>';
}
echo '</tr>';
echo '</center>';
}
}
$page_query = "SELECT * FROM tbl_call_log_detail ";
$page_result = mysqli_query($conn, $page_query);
$total_records = mysqli_num_rows($page_result);
$total_pages = ceil($total_records/$record_per_page);
$start_loop = $page;
$difference = $total_pages - $page;
if($difference <= $total_pages){
$start_loop = $total_pages - $difference;
}
$end_loop = $start_loop + 2;
if($difference > $total_pages){
$end_loop = $total_pages;
}
if($page > 1){
echo "<a href= 'dealer_call_log.php?page=1'>First</a>";
echo "<a href= 'dealer_call_log.php?page=".($page - 1)."'><<</a>";
}
for ($i = $start_loop; $i <= $end_loop; $i++){
echo "<a href= 'dealer_call_log.php?page=".$i."'>".$i."</a>";
}
if($page <= $end_loop){
echo "<a href= 'dealer_call_log.php?page=".($page + 1)."'>>></a>";
echo "<a href= 'dealer_call_log.php?page=".$total_pages."'>Last</a>";
}
if($page < 1){
$page = 1;
}
echo '</table>';
Any help would be appreciated. Thanks!