From 68f89bb42d9874764aa534b042dfde32a7c4984c Mon Sep 17 00:00:00 2001 From: Grim0o5 Date: Sun, 12 Jan 2025 20:14:21 +0545 Subject: [PATCH] filter option working along with search did some spelling changes to in the managejob php --- index.php | 136 ++++++++++++++++++++--------------- managejob.php | 6 +- search_results.php | 174 +++++++++++++++++++++++++++------------------ 3 files changed, 183 insertions(+), 133 deletions(-) diff --git a/index.php b/index.php index 05e051d..0ab8c31 100644 --- a/index.php +++ b/index.php @@ -11,27 +11,35 @@ - +
-

+

The Future of Work

Discover opportunities that match your schedule and skills in real-time.

-
- + + -
- +
+ +
- - - +
+ + + + + + + +

How It Works

diff --git a/managejob.php b/managejob.php index d9ab1db..ab90770 100644 --- a/managejob.php +++ b/managejob.php @@ -162,9 +162,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['job_title'])) {
diff --git a/search_results.php b/search_results.php index 0def023..f574afd 100644 --- a/search_results.php +++ b/search_results.php @@ -4,65 +4,68 @@ include 'connect.php'; // Check if the user is logged in if (!isset($_SESSION['email'])) { - // If not logged in, redirect to login page header("Location: login.php"); exit(); } -// Build the SQL query based on search parameters -$where_conditions = array(); -$params = array(); -$types = ""; - -// Search by job title or description -if (!empty($_GET['search'])) { - $where_conditions[] = "(job_title LIKE ? OR description LIKE ?)"; - $search_term = "%" . $_GET['search'] . "%"; - $params[] = $search_term; - $params[] = $search_term; - $types .= "ss"; -} - -// Search by location -if (!empty($_GET['location'])) { - $where_conditions[] = "location = ?"; - $params[] = $_GET['location']; - $types .= "s"; -} - -// Search by job type -if (!empty($_GET['job_type'])) { - $where_conditions[] = "job_type = ?"; - $params[] = $_GET['job_type']; - $types .= "s"; -} - -// Search by salary type -if (!empty($_GET['salary_type'])) { - $where_conditions[] = "salary LIKE ?"; - $params[] = "%" . $_GET['salary_type'] . "%"; - $types .= "s"; -} +try { + // Initialize arrays for query building + $where_conditions = []; + $params = []; + $types = ""; + + // Search by job title or description + if (!empty($_GET['search'])) { + $where_conditions[] = "(job_title LIKE ? OR job_description LIKE ?)"; + $search_term = "%" . $_GET['search'] . "%"; + $params[] = $search_term; + $params[] = $search_term; + $types .= "ss"; + } + + // Job type filter + if (!empty($_GET['job_type'])) { + $where_conditions[] = "job_type = ?"; + $params[] = $_GET['job_type']; + $types .= "s"; + } + + // Salary type filter + if (!empty($_GET['salary_type'])) { + $where_conditions[] = "salary_type = ?"; // Changed to match the exact column name + $params[] = $_GET['salary_type']; + $types .= "s"; + } + + // Skills level filter + if (!empty($_GET['skills_level'])) { + $where_conditions[] = "skills_level = ?"; + $params[] = $_GET['skills_level']; + $types .= "s"; + } + + // Construct the SQL query + $sql = "SELECT * FROM job_postings"; + + // Add WHERE clause if there are conditions + if (!empty($where_conditions)) { + $sql .= " WHERE " . implode(" AND ", $where_conditions); + } + + // Add ordering + $sql .= " ORDER BY posted_date DESC"; + + // Prepare and execute the query + $stmt = $conn->prepare($sql); + + if (!empty($params)) { + $stmt->bind_param($types, ...$params); + } + + $stmt->execute(); + $result = $stmt->get_result(); -// Search by skill level -if (!empty($_GET['skill_level'])) { - $where_conditions[] = "skill_level = ?"; - $params[] = $_GET['skill_level']; - $types .= "s"; -} - -$sql = "SELECT * FROM job_postings"; -if (!empty($where_conditions)) { - $sql .= " WHERE " . implode(" AND ", $where_conditions); -} -$sql .= " ORDER BY posted_date DESC"; - -$stmt = $conn->prepare($sql); -if (!empty($params)) { - $stmt->bind_param($types, ...$params); -} ?> - @@ -85,18 +88,16 @@ if (!empty($params)) {
execute(); - $result = $stmt->get_result(); - - if ($result->num_rows > 0) { + if ($result && $result->num_rows > 0) { while ($job = $result->fetch_assoc()) { ?>

- +
+
@@ -107,47 +108,78 @@ if (!empty($params)) {
+
-
Salary
+
Salary ()
+
- - + +
-
Posted Date
-
+
Job Type
+
-
-
+ +
+ + + +
+
Required Skills
+
+
+
+ +
- - View Details - + + View Details + +
No jobs available.

"; + echo "
"; + echo "

No Jobs Found

"; + echo "

Try adjusting your search criteria or removing some filters.

"; + echo "
"; } - $conn->close(); ?>
- +"; + echo "
"; + echo "Error details: " . htmlspecialchars($e->getMessage()); + echo "
"; + echo ""; + } + + // Close database connections + if (isset($stmt)) { + $stmt->close(); + } + if (isset($conn)) { + $conn->close(); + } +?> \ No newline at end of file