File "test.php"
Full path: /home/atrmarke/public_html/atrdemolive.site/bshop/log/log/test.php
File
size: 0.01 KB (6.44 KB bytes)
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
include("../db/cn.php");
if (isset($_GET['school_name'])) {
$schoolNameInput = $_GET['school_name'];
if (!empty($schoolNameInput)) {
// Prepare the LIKE query for addschool to fetch matching school names
$stmt1 = $connection->prepare("
SELECT school_name
FROM addschool
WHERE LOWER(TRIM(school_name)) LIKE LOWER(TRIM(?))
GROUP BY school_name
");
$likeSchoolName = "%" . $schoolNameInput . "%";
$stmt1->bind_param("s", $likeSchoolName);
$stmt1->execute();
$result1 = $stmt1->get_result();
if ($result1->num_rows > 0) {
while ($row1 = $result1->fetch_assoc()) {
$schoolName = $row1['school_name'];
// Logging for debugging purposes (optional)
error_log("Fetched school name: " . $schoolName);
// Fetch the corresponding closing date from school_closing
$stmt2 = $connection->prepare("
SELECT closing
FROM school_closing
WHERE LOWER(TRIM(school_name)) = LOWER(TRIM(?))
");
$stmt2->bind_param("s", $schoolName);
$stmt2->execute();
$result2 = $stmt2->get_result();
$closing = '';
if ($result2->num_rows > 0) {
$row2 = $result2->fetch_assoc();
$closing = $row2['closing'];
} else {
// Logging if no closing found for debugging purposes (optional)
error_log("No closing found for school: " . $schoolName);
}
// Debug Output: Display school name and closing date in the dropdown item
echo '<div class="dropdown-item" data-school-name="' . htmlspecialchars($schoolName, ENT_QUOTES) .
'" data-school-closing="' . htmlspecialchars($closing, ENT_QUOTES) . '">' .
htmlspecialchars($schoolName, ENT_QUOTES) . '</div>';
// Close the second statement
$stmt2->close();
}
} else {
// No school found
echo '<div class="dropdown-item">No School found</div>';
}
// Close the first statement
$stmt1->close();
}
// Close the database connection
$connection->close();
exit;
}
?>
<style>
#table-container-wrapper {
max-height: 390px;
overflow-y: auto;
}
.bg {
background: linear-gradient(270deg, #060606, #3C2F23);
}
.input-group-text {
font-weight: 600;
font-size: 11px;
}
.in_form {
height: 30px;
font-size: 13px;
border-color: #0A5064;
}
label {
font-size: 13.5px;
font-weight: 700;
}
.input-group-text {
font-weight: 600;
font-size: 11px;
width: 73px;
display:
}
.dropdown-menu {
max-height: 200px;
overflow-y: auto;
position: absolute;
z-index: 1000;
width: 100%;
}
.input-group {
position: relative;
}
.dropdown-item.active, .dropdown-item:active {
color: #fff;
text-decoration: none;
background-color: #0A5064;
}
</style>
<div class="col-sm-3">
<div class="form-group">
<label>School Name</label>
<input type="text" id="customer_type" class="form-control in_form" name="customer_type">
<div id="order_suggestions1" class="dropdown-menu" style="display: none;"></div>
</div>
</div>
<br><br>
<div class="col-sm-2">
<div class="form-group">
<label>Previous.B</label>
<input type="number" id="previous_b" name="previous_b" class="form-control in_form input-height">
</div>
</div>
<script>
document.getElementById("customer_type").addEventListener("input", function () {
var schoolNameInput = this.value;
if (schoolNameInput.length > 0) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "?school_name=" + encodeURIComponent(schoolNameInput), true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var suggestions = document.getElementById("order_suggestions1");
suggestions.innerHTML = xhr.responseText;
suggestions.style.display = 'block';
}
};
xhr.send();
} else {
document.getElementById("order_suggestions1").style.display = 'none';
}
});
document.getElementById("order_suggestions1").addEventListener("click", function (e) {
if (e.target && e.target.classList.contains("dropdown-item")) {
selectOrder(e.target);
}
});
document.getElementById("customer_type").addEventListener("keydown", function (e) {
var suggestions = document.getElementById("order_suggestions1");
if (suggestions.style.display === 'block') {
var items = suggestions.getElementsByClassName("dropdown-item");
if (e.key === "ArrowDown") {
currentFocus++;
addActive(items);
} else if (e.key === "ArrowUp") {
currentFocus--;
addActive(items);
} else if (e.key === "Enter") {
e.preventDefault();
if (currentFocus > -1) {
if (items[currentFocus]) {
selectOrder(items[currentFocus]);
}
}
}
}
});
function addActive(items) {
if (!items) return false;
removeActive(items);
if (currentFocus >= items.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = items.length - 1;
items[currentFocus].classList.add("active");
items[currentFocus].scrollIntoView({ block: "nearest" });
}
function removeActive(items) {
for (var i = 0; i < items.length; i++) {
items[i].classList.remove("active");
}
}
function selectOrder(item) {
var schoolName = item.getAttribute('data-school-name');
var schoolClosing = item.getAttribute('data-school-closing');
console.log("School Name:", schoolName);
console.log("School Closing:", schoolClosing);
document.getElementById("customer_type").value = schoolName;
document.getElementById("previous_b").value = schoolClosing || ''; // Populate Previous.B input field
document.getElementById("order_suggestions1").style.display = 'none';
}
</script>