problima kasi kapag nag sesearch ako halimbawa ay nasa pagination number 1 ako or page number 1 kapag mag sesearch ako yun laman lang ng pagination 1 o page 1 ang lumalabas di nakakasama yun data sa page number 2 and soon kahit meron nman laman o data dun sa page 2 and soon ..halimbawa is mag ssearch ako ng tubig sa page 1 may tatlo tubig at page 2 dalawa at page 3 lima ngaun nasa page 1 ako mag sesearch ang lumalabas lang is tatlo tubig na dapat ay lumabas overall is wala tubig dapat..
ito code ko:
<?php
include '../partials/newnav.php';
?>
<?php
include '../partials/header.php';
?>
<?php
// Start Pagination php
if (isset($_GET['page_no']) && $_GET['page_no'] !== "") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}
$total_records_per_page = 20;
$numbers_per_page = 10;
$offset = ($page_no - 1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$stmt = $con-> prepare("SELECT COUNT(*) AS total_records FROM registration INNER JOIN lddap ON registration.payee_name = lddap.payee_name WHERE registration.email_address = ? AND registration.password = ?");
$stmt->bind_param('ss', $email_address , $password);
$stmt->execute();
$result = $stmt->get_result();
$records = $result->fetch_assoc();
$total_records = $records['total_records'];
$total_no_of_page = ceil($total_records / $total_records_per_page);
$start_number = max($page_no - floor ($numbers_per_page / 2), 1);
$end_number = min($start_number + $numbers_per_page - 1, $total_no_of_page);
// End Pagination php
// Start Query to Database
$searchKeyword = isset($_GET['search']) ? $_GET['search'] : '';
// Construct the base SQL query without pagination
$baseSql = "SELECT registration.payee_name, lddap.particular, lddap.amount, lddap.lddap_ada, lddap.date FROM registration INNER JOIN lddap ON registration.payee_name = lddap.payee_name WHERE registration.email_address = '$email_address' AND registration.password = '$password'";
// Add the search condition if keyword is present
if (!empty($searchKeyword)) {
$baseSql .= " AND (registration.payee_name LIKE '%" . $searchKeyword . "%' OR lddap.particular LIKE '%" . $searchKeyword . "%')";
}
// Perform the search across all records
$searchResult = $con->query($baseSql);
// Apply pagination to the search results
$sql = $baseSql . " ORDER BY STR_TO_DATE(lddap.date, '%m/%d/%Y') DESC LIMIT $offset , $total_records_per_page";
$result = $con->query($sql);
// End Query to database
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... (your head content) ... -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tracking</title>
<link rel = "stylesheet" href ="../css/style.css">
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now." rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="You do not have permission to view the full content of this post. Log in or register now.">
<script type="text/javascript" src="You do not have permission to view the full content of this post. Log in or register now."></script>
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now.">
<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/dist/easy-table.min.js"></script>
</head>
<body>
<div class="container">
<form class="mt-3" method="GET" action="">
<div class="col-sm-6">
<div class="input-group input-group-sm w-50 mb-3 custom " >
<span class="input-group-text" id="basic-addon1"><i class="bi bi-search"></i></span>
<input type="hidden" name="page_no" value="<?= $page_no; ?>">
<input type="search" class="form-control" name="search" id="search" placeholder="Search..." aria-label="Username" aria-describedby="basic-addon1" value="<?= isset($_GET['search']) ? $_GET['search'] : ''; ?>">
</div>
</div>
</form>
<div id="searchresult"></div>
<!-- Display the results from the search query -->
<table class="tableldap" id="livesearch">
<h2 class="caption">LDDAP-ADA SUMMARY</h2>
<thead>
<tr>
<th scope="col">Payee Name</th>
<th scope="col">Particular</th>
<th scope="col">Amount</th>
<th scope="col">LDDAP ADA</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
<?php
if ($searchResult->num_rows > 0) {
while ($row = $searchResult->fetch_assoc()) {
$payee_name = $row["payee_name"];
$particular = $row["particular"];
$amount = $row["amount"];
$lddap_ada = $row["lddap_ada"];
$date = $row["date"];
?>
<tr class="trldap">
<td class="tdldap" data-label="Payee Name:"><?php echo $payee_name; ?></td>
<td class="tdldap" data-label="Particular:"><?php echo $particular; ?></td>
<td class="tdldap" data-label="Amount:"><?php echo $amount; ?></a></td>
<td class="tdldap" data-label="Lddap-Ada:"><?php echo $lddap_ada; ?></td>
<td class="tdldap" data-label="Date:"><?php echo $date; ?></td>
</tr>
<?php
}
} else {
echo "No results found.";
}
$con->close();
?>
</tbody>
</table>
<!-- Pagination -->
<div class="pt-3">
<nav aria-label="Page navigation example">
<div class= "container p-10">
<strong>Page <?= $page_no; ?> of <?= $total_records_per_page;?>
<div class="mt-2">
<ul class="pagination">
<li class ="page-item"><a class="page-link" <?= ($page_no <= 1) ? 'disabled style="background-color:gray "' : '' ; ?> <?= ($page_no > 1) ? 'href=?page_no=' .$previous_page : '' ; ?>>Previous</a></li>
<?php for ($counter = $start_number ; $counter <= $end_number; $counter++) { ?>
<?php if ($page_no != $counter){ ?>
<li class ="page-item"><a class="page-link" href="?page_no=<?= $counter; ?>&search=<?= $searchKeyword; ?>"><?= $counter; ?></a></li>
<?php } else { ?>
<li class ="page-item"><a class="page-link active" ><?= $counter; ?></a></li>
<?php }?>
<?php }?>
<li class ="page-item"><a class="page-link" <?= ($page_no >= $total_no_of_page) ? 'disabled style="background-color:gray"' : '' ; ?> <?= ($page_no < $total_no_of_page) ? 'href=?page_no=' .$next_page . '&search=' . $searchKeyword : '' ; ?>>Next</a></li>
</ul>
</div>
</strong>
</div>
</nav>
</div>
</div>
<!-- End Pagination -->
<script src="../js/style.js"></script>
<script src="../js/bootstrap.bundle.js"></script>
<script src="../ajax/jquery2.js"></script>
<script src="../ajax/sweetalert2.all.js"></script>
<?php
include "../partials/footer.php";
?>
<!-- ... (your remaining HTML content) ... -->
<script type="text/javascript">
// search
// start
$(document).ready(function () {
$('#search').on("keyup", function () {
var value = $(this).val().toLowerCase();
$('#livesearch tr').filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
});
</script>
</body>
</html>
ito code ko:
<?php
include '../partials/newnav.php';
?>
<?php
include '../partials/header.php';
?>
<?php
// Start Pagination php
if (isset($_GET['page_no']) && $_GET['page_no'] !== "") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}
$total_records_per_page = 20;
$numbers_per_page = 10;
$offset = ($page_no - 1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$stmt = $con-> prepare("SELECT COUNT(*) AS total_records FROM registration INNER JOIN lddap ON registration.payee_name = lddap.payee_name WHERE registration.email_address = ? AND registration.password = ?");
$stmt->bind_param('ss', $email_address , $password);
$stmt->execute();
$result = $stmt->get_result();
$records = $result->fetch_assoc();
$total_records = $records['total_records'];
$total_no_of_page = ceil($total_records / $total_records_per_page);
$start_number = max($page_no - floor ($numbers_per_page / 2), 1);
$end_number = min($start_number + $numbers_per_page - 1, $total_no_of_page);
// End Pagination php
// Start Query to Database
$searchKeyword = isset($_GET['search']) ? $_GET['search'] : '';
// Construct the base SQL query without pagination
$baseSql = "SELECT registration.payee_name, lddap.particular, lddap.amount, lddap.lddap_ada, lddap.date FROM registration INNER JOIN lddap ON registration.payee_name = lddap.payee_name WHERE registration.email_address = '$email_address' AND registration.password = '$password'";
// Add the search condition if keyword is present
if (!empty($searchKeyword)) {
$baseSql .= " AND (registration.payee_name LIKE '%" . $searchKeyword . "%' OR lddap.particular LIKE '%" . $searchKeyword . "%')";
}
// Perform the search across all records
$searchResult = $con->query($baseSql);
// Apply pagination to the search results
$sql = $baseSql . " ORDER BY STR_TO_DATE(lddap.date, '%m/%d/%Y') DESC LIMIT $offset , $total_records_per_page";
$result = $con->query($sql);
// End Query to database
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... (your head content) ... -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tracking</title>
<link rel = "stylesheet" href ="../css/style.css">
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now." rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="You do not have permission to view the full content of this post. Log in or register now.">
<script type="text/javascript" src="You do not have permission to view the full content of this post. Log in or register now."></script>
<link rel="stylesheet" href="You do not have permission to view the full content of this post. Log in or register now.">
<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/dist/easy-table.min.js"></script>
</head>
<body>
<div class="container">
<form class="mt-3" method="GET" action="">
<div class="col-sm-6">
<div class="input-group input-group-sm w-50 mb-3 custom " >
<span class="input-group-text" id="basic-addon1"><i class="bi bi-search"></i></span>
<input type="hidden" name="page_no" value="<?= $page_no; ?>">
<input type="search" class="form-control" name="search" id="search" placeholder="Search..." aria-label="Username" aria-describedby="basic-addon1" value="<?= isset($_GET['search']) ? $_GET['search'] : ''; ?>">
</div>
</div>
</form>
<div id="searchresult"></div>
<!-- Display the results from the search query -->
<table class="tableldap" id="livesearch">
<h2 class="caption">LDDAP-ADA SUMMARY</h2>
<thead>
<tr>
<th scope="col">Payee Name</th>
<th scope="col">Particular</th>
<th scope="col">Amount</th>
<th scope="col">LDDAP ADA</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
<?php
if ($searchResult->num_rows > 0) {
while ($row = $searchResult->fetch_assoc()) {
$payee_name = $row["payee_name"];
$particular = $row["particular"];
$amount = $row["amount"];
$lddap_ada = $row["lddap_ada"];
$date = $row["date"];
?>
<tr class="trldap">
<td class="tdldap" data-label="Payee Name:"><?php echo $payee_name; ?></td>
<td class="tdldap" data-label="Particular:"><?php echo $particular; ?></td>
<td class="tdldap" data-label="Amount:"><?php echo $amount; ?></a></td>
<td class="tdldap" data-label="Lddap-Ada:"><?php echo $lddap_ada; ?></td>
<td class="tdldap" data-label="Date:"><?php echo $date; ?></td>
</tr>
<?php
}
} else {
echo "No results found.";
}
$con->close();
?>
</tbody>
</table>
<!-- Pagination -->
<div class="pt-3">
<nav aria-label="Page navigation example">
<div class= "container p-10">
<strong>Page <?= $page_no; ?> of <?= $total_records_per_page;?>
<div class="mt-2">
<ul class="pagination">
<li class ="page-item"><a class="page-link" <?= ($page_no <= 1) ? 'disabled style="background-color:gray "' : '' ; ?> <?= ($page_no > 1) ? 'href=?page_no=' .$previous_page : '' ; ?>>Previous</a></li>
<?php for ($counter = $start_number ; $counter <= $end_number; $counter++) { ?>
<?php if ($page_no != $counter){ ?>
<li class ="page-item"><a class="page-link" href="?page_no=<?= $counter; ?>&search=<?= $searchKeyword; ?>"><?= $counter; ?></a></li>
<?php } else { ?>
<li class ="page-item"><a class="page-link active" ><?= $counter; ?></a></li>
<?php }?>
<?php }?>
<li class ="page-item"><a class="page-link" <?= ($page_no >= $total_no_of_page) ? 'disabled style="background-color:gray"' : '' ; ?> <?= ($page_no < $total_no_of_page) ? 'href=?page_no=' .$next_page . '&search=' . $searchKeyword : '' ; ?>>Next</a></li>
</ul>
</div>
</strong>
</div>
</nav>
</div>
</div>
<!-- End Pagination -->
<script src="../js/style.js"></script>
<script src="../js/bootstrap.bundle.js"></script>
<script src="../ajax/jquery2.js"></script>
<script src="../ajax/sweetalert2.all.js"></script>
<?php
include "../partials/footer.php";
?>
<!-- ... (your remaining HTML content) ... -->
<script type="text/javascript">
// search
// start
$(document).ready(function () {
$('#search').on("keyup", function () {
var value = $(this).val().toLowerCase();
$('#livesearch tr').filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
});
</script>
</body>
</html>