Skip to content

Commit

Permalink
feat: "added searchbar in box.php"
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranzafar4343 committed Sep 10, 2024
1 parent e359a34 commit 2b7a67a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 48 deletions.
16 changes: 8 additions & 8 deletions Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

?>

<!DOCTYPE html>
Expand Down Expand Up @@ -451,9 +450,10 @@
<tbody style="table-layout: fixed;">

<?php
$counter = 1; // Initialize counter
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . htmlspecialchars($row["comp_id"]) . "</td>";
echo "<td>" . $counter++ . "</td>";
?>
<td>

Expand Down
88 changes: 70 additions & 18 deletions box.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
// }

?>

<!DOCTYPE html>
Expand Down Expand Up @@ -91,6 +98,40 @@
<style>
/* Custom CSS to decrease font size of the table */

/* Basic styling for search bar */
input.btn.btn-success {
margin-left: 7px;
height: 41px;
padding: 2%;
padding-top: 3px;
padding-bottom: 3px;
text-align: center;
justify-items: center;

}

.search-container {
margin: 50px;
margin-left: 320px;
margin-bottom: 3px !important;
}

#main {

margin-top: 0 !important;
}

input[type="text"] {
padding: 8px;
font-size: 0.9rem;
width: 363px;
}

input[type="submit"] {
padding: 10px 20px;
font-size: 16px;
}

.pagetitle {
display: flex;
width: 989px;
Expand Down Expand Up @@ -235,7 +276,7 @@
box-shadow: 0px 0 30px rgba(1, 41, 112, 0.1);
background-color: white;
font-size: 0.8rem;
margin-top: 30px;

}

.company-name:active {
Expand Down Expand Up @@ -488,6 +529,12 @@
<!--new table design-->
<button id="fixedButtonBranch" type="button" onclick="window.location.href = 'createBox.php';" class="btn btn-primary mb-3">Add box</button>

<div class="search-container">
<form id="searchForm" action="" method="GET">
<input type="text" id="searchInput" name="query" placeholder="Enter box name or scan barcode..." autofocus>
<input type="submit" value="Search" class="btn btn-success btn-success">
</form>
</div>
<main id="main" class="main">

<div class="col-12">
Expand Down Expand Up @@ -588,10 +635,15 @@

<!-- Template Main JS File -->
<script src="assets/js/main.js"></script>




<script>
// Listen for the Enter key press
document.getElementById("searchInput").addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault(); // Prevent default form submission
document.getElementById("searchForm").submit(); // Manually submit the form
}
});
</script>
</body>

</html>
3 changes: 2 additions & 1 deletion create.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
exit();
}

include "db.php";

$email = $_SESSION['email'];
//get user name and email from register table
$getAdminData = "SELECT * FROM register WHERE email = '$email'";
Expand All @@ -21,7 +23,6 @@
$adminEmail=$row2['email'];
}

include "db.php";

if (isset($_POST['submit'])) {
$comp_name = mysqli_real_escape_string($conn, $_POST['comp_name']);
Expand Down
24 changes: 3 additions & 21 deletions showItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
box-shadow: 0px 0 30px rgba(1, 41, 112, 0.1);
background-color: white;
font-size: 0.8rem;

}

.company-name:active {
Expand Down Expand Up @@ -555,10 +556,11 @@

<div class="search-container">
<form id="searchForm" action="" method="GET">
<input type="text" id="searchInput" name="query" placeholder="Enter product name or scan barcode" autofocus>
<input type="text" id="searchInput" name="query" placeholder="Enter item name or scan barcode..." autofocus>
<input type="submit" value="Search" class="btn btn-success btn-success">
</form>
</div>

<main id="main" class="main">

<div class="col-12">
Expand Down Expand Up @@ -707,26 +709,6 @@ function uploadImage(comp_id) {
initMDB({
Ripple
});

// function confirmDelete() {
// // Display a confirmation dialog
// var confirmation = confirm("Are you sure you want to delete this record?");

// if (confirmation) {
// // User clicked OK, proceed with deletion
// deleteRecord();
// } else {
// // User clicked Cancel, do nothing
// console.log("Record deletion canceled.");
// }
// }

// function deleteRecord() {
// // Your deletion logic here
// console.log("Record deleted.");
// // Example: You might want to make an AJAX request to delete the record from the server
// // fetch('/delete-record', { method: 'POST' }).then(response => response.json()).then(data => console.log(data));
// }
</script>


Expand Down

0 comments on commit 2b7a67a

Please sign in to comment.