[ 'text' => 'You have already applied for this task.', 'type' => 'warning' ], 'owner_cannot_apply' => [ 'text' => 'You cannot apply for your own task.', 'type' => 'warning' ], 'applied_successfully' => [ 'text' => 'You have successfully applied for the task.', 'type' => 'success' ], 'application_failed' => [ 'text' => 'There was an error submitting your application.', 'type' => 'danger' ] ]; // Fetch tasks from the database try { $search = $_GET['search'] ?? ''; $category = $_GET['category'] ?? ''; $location = $_GET['location'] ?? ''; $sql = "SELECT t.*, u.id as user_id_poster, u.full_name as user_name FROM tasks t JOIN users u ON t.user_id = u.id WHERE t.status = 'open'"; $params = []; if (!empty($search)) { $sql .= " AND (t.title LIKE :search OR t.description LIKE :search)"; $params[':search'] = '%' . $search . '%'; } if (!empty($category)) { $sql .= " AND t.category LIKE :category"; $params[':category'] = '%' . $category . '%'; } if (!empty($location)) { $sql .= " AND t.location LIKE :location"; $params[':location'] = '%' . $location . '%'; } $sql .= " ORDER BY t.created_at DESC"; $stmt = db()->prepare($sql); $stmt->execute($params); $tasks = $stmt->fetchAll(); } catch (PDOException $e) { // Handle database error gracefully error_log($e->getMessage()); $tasks = []; } ?>
No tasks found matching your criteria. Try broadening your search!