$page = 1;
if(!empty($_GET['page'])) {
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
if(false === $page) {
$page = 1;
}
}
if (isset($_GET['source']) && is_numeric
($_GET['source'])) {//already been calculated
$source = $_GET['source'];
}else{
$source = $_POST['source'];
}
if (isset($_GET['dst']) && is_numeric
($_GET['dst'])) {//already been calculated
$dst = $_GET['dst'];
}else{
$dst = $_POST['dst'];
}
if (!empty($_POST['from_date']))
{
$from_date = $_POST['from_date'];
}
elseif (!empty($_GET['from_date']) )
{
$from_date = $_GET['from_date'];
}
else
{
$from_date = date("Y-m-d 00:00:00");
}
if (!empty($_POST['to_date']))
{
$to_date = $_POST['to_date'];
}
elseif (!empty($_GET['to_date']))
{
$to_date = $_GET['to_date'];
}
else
{
$to_date = date("Y-m-d 23:59:59");
}
$connect = mysqli_connect("localhost", "root", "Edger00t@2025", "eva");
$query ="SELECT * FROM evagent where phone like '%$source%' and evagentNum like '%$dst%' and (timestamp between '$from_date' and '$to_date') ORDER BY timestamp desc";
$result = mysqli_query($connect, $query);
$row_count = mysqli_num_rows($result);
//mysqli_free_result($result);
$items_per_page = 10;
$offset = ($page - 1) * $items_per_page;
$page_count = 0;
if (0 === $row_count) { echo "there is no match records";
// maybe show some error since there is nothing in your table
} else {
// determine page_count
$page_count = (int)ceil($row_count / $items_per_page);
// double check that request page is in range
if($page > $page_count) {
// error to user, maybe set page to 1
$page = 1;
}
}
// make your LIMIT query here as shown above
// later when outputting page, you can simply work with $page and $page_count to output links
// for example
$query1 ="SELECT * FROM evagent where phone like '%$source%' and evagentNum like '%$dst%' and (timestamp between '$from_date' and '$to_date') ORDER BY timestamp desc limit $offset , $items_per_page";
$result1 = mysqli_query($connect, $query1);
//echo $query1 ;
<!DOCTYPE html>
<html>
<head>
<title>Agent Survey</title>
<link rel="stylesheet" href="bootstrap.min.css" />
<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
color: #333;
margin: 0;
padding: 0;
}
.container {
width: 90%;
margin: 20px auto;
background-color: white;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 20px;
border-radius: 8px;
}
h3 {
color: #572a83;
font-size: 24px;
text-align: center;
}
form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-bottom: 20px;
}
form p {
flex: 1 1 30%;
margin: 0 10px;
}
label {
font-weight: bold;
margin-bottom: 5px;
display: block;
}
input.form-control, input[type="submit"] {
border: 2px solid #572a83;
border-radius: 4px;
padding: 10px;
width: 100%;
}
input[type="submit"] {
background-color: #572a83;
color: white;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s;
}
input[type="submit"]:hover {
background-color: #452160;
}
.table-responsive1 {
margin-top: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
table th, table td {
padding: 12px;
text-align: left;
}
table th {
background-color: #572a83;
color: white;
}
table tr:nth-child(even) {
background-color: #f2f2f2;
}
table tr:hover {
background-color: #ddd;
}
a {
color: #572a83;
text-decoration: none;
font-weight: bold;
}
a:hover {
color: hotpink;
}
a:visited {
color: green;
}
a:active {
color: pink;
font-weight: bold;
}
.pagination {
text-align: center;
margin-top: 20px;
}
.pagination a {
padding: 8px 16px;
background-color: #572a83;
color: white;
margin: 0 2px;
border-radius: 4px;
text-decoration: none;
}
.pagination a:hover {
background-color: #452160;
}
.pagination a.current-page {
background-color: #ffcb05;
color: black;
}
</style>
</head>
<body>
<div class="container">
<form class="col-md-16" action="index.php" method="post">
<p>
<label for="source">Source:</label>
<input id="source" type="text" name="source" class="form-control" placeholder="Phone" value="echo htmlspecialchars($source);">
</p>
<p>
<label for="from_date">Start Date:</label>
<input type="datetime-local" name="from_date" id="from_date" class="form-control" value="echo htmlspecialchars($from_date);">
</p>
<p>
<label for="to_date">End Date:</label>
<input type="datetime-local" name="to_date" id="to_date" class="form-control" value="echo htmlspecialchars($to_date);">
</p>
<p style="flex: 1 1 100%; text-align: right; margin-top: 22px;">
<input type="submit" name="filter" value="Filter" class="btn btn-secondary">
</p>
</form>
<form method="post" action="export.php" align="center">
<input type="hidden" name="from_date" value="echo htmlspecialchars($from_date);">
<input type="hidden" name="to_date" value="echo htmlspecialchars($to_date);">
<input type="hidden" name="source" value="echo htmlspecialchars($source);">
<input type="hidden" name="dst" value="echo htmlspecialchars($dst);">
<input type="submit" name="export" value="CSV Export" class="btn btn-info">
</form>
<div class="table-responsive1" id="Agent_survey">
<table class="table table-bordered1">
<thead>
<tr>
<th>Date</th>
<th>Phone</th>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
</tr>
</thead>
<tbody>
while($row = mysqli_fetch_array($result1)) {
<tr>
<td>echo htmlspecialchars($row["timestamp"]);</td>
<td>echo htmlspecialchars($row["phone"]);</td>
<td>echo htmlspecialchars($row["eva1"]);</td>
<td>echo htmlspecialchars($row["eva2"]);</td>
<td>echo htmlspecialchars($row["eva3"]);</td>
<td>echo htmlspecialchars($row["eva4"]);</td>
</tr>
}
</tbody>
</table>
<div class="pagination">
// Pagination logic
for ($i = 1; $i <= $page_count; $i++) {
if ($i == $page) {
echo '<a class="current-page">' . $i . '</a>';
} else {
echo '<a href="index.php?page=' . $i . '&source=' . $source . '&dst=' . $dst . '&from_date=' . $from_date . '&to_date=' . $to_date . '">' . $i . '</a>';
}
}
</div>
</div>
</div>
</body>
</html>
© 2023 Quttera Ltd. All rights reserved.