prepare('SELECT id, full_name, email, created_at FROM users WHERE id = :id'); $stmt->execute([':id' => $profileId]); $profileUser = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { die("Database error: Could not retrieve user profile."); } if (!$profileUser) { // Handle user not found header("Location: index.php?message=user_not_found"); exit(); } // Fetch tasks posted by the user try { $stmt = $pdo->prepare('SELECT * FROM tasks WHERE user_id = :user_id ORDER BY created_at DESC'); $stmt->execute([':user_id' => $profileId]); $postedTasks = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { die("Database error: Could not retrieve posted tasks."); } // Fetch tasks the user has completed (i.e., their application was accepted) try { $stmt = $pdo->prepare( 'SELECT t.* FROM tasks t JOIN applications a ON t.id = a.task_id WHERE a.user_id = :user_id AND a.status = \'accepted\' ORDER BY t.created_at DESC' ); $stmt->execute([':user_id' => $profileId]); $completedTasks = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { die("Database error: Could not retrieve completed tasks."); } $pageTitle = htmlspecialchars($profileUser['full_name']) . "'s Profile"; include 'shared/header.php'; ?>