What's new

Search pafix naman po

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
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>
 
The issue you're facing is that when you search for a keyword on page 1, the search results only show the data from page 1. However, you expect the search results to include data from all pages.

To fix this issue, you need to modify your SQL query to include the search condition, regardless of the page number. Currently, you only add the search condition when the keyword is present, but you need to add it in all cases.

Replace the following code:

PHP:
// 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 . "%')";
}

With the following code:

PHP:
// Construct the base SQL query with 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 . "%')";
}

// Apply pagination to the SQL query
$baseSql .= " ORDER BY STR_TO_DATE(lddap.date, '%m/%d/%Y') DESC LIMIT $offset , $total_records_per_page";

This will ensure that the search condition is always added to the SQL query, regardless of the page number.
 
The issue you're facing is that when you search for a keyword on page 1, the search results only show the data from page 1. However, you expect the search results to include data from all pages.

To fix this issue, you need to modify your SQL query to include the search condition, regardless of the page number. Currently, you only add the search condition when the keyword is present, but you need to add it in all cases.

Replace the following code:

PHP:
// 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 . "%')";
}

With the following code:

PHP:
// Construct the base SQL query with 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 . "%')";
}

// Apply pagination to the SQL query
$baseSql .= " ORDER BY STR_TO_DATE(lddap.date, '%m/%d/%Y') DESC LIMIT $offset , $total_records_per_page";

This will ensure that the search condition is always added to the SQL query, regardless of the page number.
wala pa rin ganun pa rin ito updated 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 . "%')";
}

// Apply pagination to the SQL query
$baseSql .= " ORDER BY STR_TO_DATE(lddap.date, '%m/%d/%Y') DESC LIMIT $offset , $total_records_per_page";
$result = $con->query($baseSql);
// 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 ($result->num_rows > 0) {
while ($row = $result->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>
 
pwede mo naman palitan ang design ng datatables.
pano po sir kasi kapag design ng Datatables is meron sya input na search, at pagination ngayon kapag iniinput ko yun css mula sa datatable at kung anu yun design nya is yun output ngayon gusto ko ilipat yun search ba nya kaso pano nga e diko alam kung anu class="" yun ginamit dun at diko makita

pwede mo naman palitan ang design ng datatables.
kasi binigay lang ng dataTable is code ng javascript at html ng table..wala css meron is link ng css e gusto ko sana e customixzed
 
Last edited:
pano po sir kasi kapag design ng Datatables is meron sya input na search, at pagination ngayon kapag iniinput ko yun css mula sa datatable at kung anu yun design nya is yun output ngayon gusto ko ilipat yun search ba nya kaso pano nga e diko alam kung anu class="" yun ginamit dun at diko makita


kasi binigay lang ng dataTable is code ng javascript at html ng table..wala css meron is link ng css e gusto ko sana e customixzed
You do not have permission to view the full content of this post. Log in or register now.
 
You do not have permission to view the full content of this post. Log in or register now.
bigyan mo nga ako sir ng sample po kasi ito lang laman na binigay ni Data Table
<table id="myTable" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
</table>

pano ko may sstyling yun Search button at Showing 1 to 10 of 57 entries anu ipapahawak ko sa kanila anu id anu class

You do not have permission to view the full content of this post. Log in or register now.
bigyan mo nga po ako sir clue po kung anu ipapahawak ko sa mga yan sir
 

Similar threads

Back
Top