diff --git a/dashboard.php b/dashboard.php index ccc1094..19cdd08 100644 --- a/dashboard.php +++ b/dashboard.php @@ -27,11 +27,15 @@ foreach ($all_skills as $skill) { $skills_by_category[$skill['category']][] = $skill; } -// Hardcoded enrolled skills for now -$enrolled_skills = [ - ['title' => 'Introduction to Python', 'progress' => 60, 'thumbnail' => 'assets/images/python.png'], - ['title' => 'Web Development Basics', 'progress' => 25, 'thumbnail' => 'assets/images/webdev.png'], -]; +// Fetch enrolled skills for the current user +$stmt = db()->prepare(" + SELECT s.id, s.title, s.category, s.thumbnail, e.progress + FROM enrollments e + JOIN skills s ON e.skill_id = s.id + WHERE e.user_id = ? +"); +$stmt->execute([$userId]); +$enrolled_skills = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> @@ -97,7 +101,14 @@ $enrolled_skills = [

My Enrolled Skills

-

You are not enrolled in any skills yet. Explore the skills below to get started!

+
+
+
+

You haven’t enrolled in any skills yet. Explore new skills to start learning!

+ Explore Skills +
+
+
@@ -105,10 +116,11 @@ $enrolled_skills = [ <?php echo htmlspecialchars($skill['title']); ?>
diff --git a/db/migrations/006_rename_user_skills_to_enrollments.sql b/db/migrations/006_rename_user_skills_to_enrollments.sql new file mode 100644 index 0000000..b78ebc9 --- /dev/null +++ b/db/migrations/006_rename_user_skills_to_enrollments.sql @@ -0,0 +1,16 @@ +-- This migration cleans up previous attempts and creates the enrollments table correctly. +DROP TABLE IF EXISTS `user_skills`; +DROP TABLE IF EXISTS `enrollments`; + +CREATE TABLE `enrollments` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) unsigned NOT NULL, + `skill_id` int(11) NOT NULL, + `progress` int(11) NOT NULL DEFAULT 0, + `date_enrolled` DATETIME NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`), + KEY `skill_id` (`skill_id`), + CONSTRAINT `enrollments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, + CONSTRAINT `enrollments_ibfk_2` FOREIGN KEY (`skill_id`) REFERENCES `skills` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; diff --git a/learn.php b/learn.php new file mode 100644 index 0000000..b8f10cb --- /dev/null +++ b/learn.php @@ -0,0 +1,46 @@ +prepare("SELECT * FROM skills WHERE id = ?"); +$stmt->execute([$skill_id]); +$skill = $stmt->fetch(PDO::FETCH_ASSOC); + +if (!$skill) { + // or redirect to dashboard with an error + die('Skill not found!'); +} + +// Basic page layout +?> + + + + + + Learning: <?php echo htmlspecialchars($skill['title']); ?> + + + + +
+ Back to Dashboard +

+

+
+

+
+

Course Content

+

(Content for this course will be added soon.)

+
+
+ +