From 2b7a67a629c130b6a9f7c970c5891ed9a148e668 Mon Sep 17 00:00:00 2001 From: Kamran Zafar Date: Wed, 11 Sep 2024 00:56:53 +0500 Subject: [PATCH] feat: "added searchbar in box.php" --- Companies.php | 16 +++++----- box.php | 88 ++++++++++++++++++++++++++++++++++++++++----------- create.php | 3 +- showItems.php | 24 ++------------ 4 files changed, 83 insertions(+), 48 deletions(-) diff --git a/Companies.php b/Companies.php index ba322d9..a27cea9 100644 --- a/Companies.php +++ b/Companies.php @@ -8,23 +8,22 @@ header("Location: pages-login.php"); exit(); } -include 'db.php'; // Include the database connection +include "db.php"; // Include the database connection + +$sql = "SELECT comp_id, comp_name, phone, email, password, image, city, state, country, registration, expiry FROM compani"; +$result = $conn->query($sql); + $email = $_SESSION['email']; //get user name and email from register table $getAdminData = "SELECT * FROM register WHERE email = '$email'"; $resultData = mysqli_query($conn, $getAdminData); -if ($resultData->num_rows > 0) { +if ($resultData -> num_rows > 0) { $row2 = $resultData->fetch_assoc(); $adminName = $row2['name']; $adminEmail = $row2['email']; } - - -$sql = "SELECT comp_id, comp_name, phone, email, password, image, city, state, country, registration, expiry FROM compani"; -$result = $conn->query($sql); - ?> @@ -451,9 +450,10 @@ fetch_assoc()) { echo ""; - echo "" . htmlspecialchars($row["comp_id"]) . ""; + echo "" . $counter++ . ""; ?> diff --git a/box.php b/box.php index eac1692..bd9a006 100644 --- a/box.php +++ b/box.php @@ -21,22 +21,29 @@ $adminEmail = $row2['email']; } -// Fetch box of the company -$sql = "SELECT * FROM box"; -$result = $conn->query($sql); -if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - $companiID_FK = $row['companiID_FK']; -} -$sql2 = "Select * from compani where comp_id= $companiID_FK"; -$result2 = $conn->query($sql2); -$comp_name = ""; -if ($result2->num_rows > 0) { - $row2 = $result2->fetch_assoc(); - $comp_name = $row2['comp_name']; +// Initialize query condition +$searchQuery = ""; +if (isset($_GET['query']) && !empty($_GET['query'])) { + $searchQuery = mysqli_real_escape_string($conn, $_GET['query']); + + // Search query: match barcode exactly or item name partially + $sql = "SELECT * FROM box WHERE barcode = '$searchQuery' OR box_name LIKE '%$searchQuery%'"; +} else { + // Default query if no search is performed + $sql = "SELECT * FROM box"; } +$result = $conn->query($sql); + +// $sql2 = "Select * from compani where comp_id= $companiID_FK"; +// $result2 = $conn->query($sql2); +// $comp_name = ""; +// if ($result2->num_rows > 0) { +// $row2 = $result2->fetch_assoc(); +// $comp_name = $row2['comp_name']; +// } + ?> @@ -91,6 +98,40 @@