How to develop Projects(OLP) Using PHP and Mysql Part 11

Rashmi Mishra
0

 

How to develop Projects(OLP)

 Using PHP and Mysql 

Part 11


9️ Online Learning Platform

 Next Module: Lesson Access and Learning Progress

🎯 Purpose:

To allow students to view lessons, track their progress, and optionally test their understanding through quizzes.


 Functionalities to Implement:

For Students:

  • 📖 View lesson content (text, video, PDF, etc.)
  •  Mark lesson as completed
  • 📊 Track learning progress per course/module
  • 📝 Attempt quizzes (optional at end of lessons)
  • 📂 Download supporting materials (if provided)

For Instructors:

  • 📄 View which students have completed each lesson
  • 📈 Monitor student progress
  • ✍️ Add quizzes or assessments to lessons (optional)

📁 Suggested File/Folder Structure:

/learning/

── view_lesson.php           # Display lesson content

── mark_complete.php         # Mark a lesson as completed

── progress_tracker.php      # Show student’s learning progress

── lesson_quiz.php           # Quiz or assessment for a lesson (optional)

── submit_quiz.php           # Handle quiz submission


Database Tables:

First, create these tables in MySQL:

CREATE TABLE lesson_progress (

    id INT AUTO_INCREMENT PRIMARY KEY,

    student_id INT NOT NULL,

    lesson_id INT NOT NULL,

    status ENUM('Not Started', 'In Progress', 'Completed') DEFAULT 'Not Started',

    completed_at TIMESTAMP NULL,

    FOREIGN KEY (student_id) REFERENCES users(id),

    FOREIGN KEY (lesson_id) REFERENCES lessons(id)

);

 

CREATE TABLE quizzes (

    id INT AUTO_INCREMENT PRIMARY KEY,

    lesson_id INT NOT NULL,

    question TEXT NOT NULL,

    option_a VARCHAR(255),

    option_b VARCHAR(255),

    option_c VARCHAR(255),

    option_d VARCHAR(255),

    correct_option CHAR(1),

    FOREIGN KEY (lesson_id) REFERENCES lessons(id)

);

 

CREATE TABLE quiz_attempts (

    id INT AUTO_INCREMENT PRIMARY KEY,

    student_id INT NOT NULL,

    quiz_id INT NOT NULL,

    selected_option CHAR(1),

    is_correct BOOLEAN,

    attempted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (student_id) REFERENCES users(id),

    FOREIGN KEY (quiz_id) REFERENCES quizzes(id)

);


💻 /learning/view_lesson.php
To display the lesson content.

<?php

session_start();

$conn = new mysqli("localhost", "root", "", "learning_platform");

 

$lesson_id = $_GET['lesson_id'];

$result = $conn->query("SELECT * FROM lessons WHERE id = $lesson_id");

 

if ($row = $result->fetch_assoc()) {

    echo "<h2>{$row['title']}</h2>";

    echo "<p>{$row['content']}</p>";

    echo "<a href='mark_complete.php?lesson_id=$lesson_id'>Mark as Completed</a>";

} else {

    echo "Lesson not found!";

}

?>


💻 /learning/mark_complete.php
To mark a lesson as completed.

<?php

session_start();

$conn = new mysqli("localhost", "root", "", "learning_platform");

$student_id = $_SESSION['user_id'];

$lesson_id = $_GET['lesson_id'];

 

// Check if record exists

$query = "SELECT * FROM lesson_progress WHERE student_id = ? AND lesson_id = ?";

$stmt = $conn->prepare($query);

$stmt->bind_param("ii", $student_id, $lesson_id);

$stmt->execute();

$result = $stmt->get_result();

 

if ($result->num_rows > 0) {

    $update = $conn->prepare("UPDATE lesson_progress SET status = 'Completed', completed_at = NOW() WHERE student_id = ? AND lesson_id = ?");

    $update->bind_param("ii", $student_id, $lesson_id);

    $update->execute();

} else {

    $insert = $conn->prepare("INSERT INTO lesson_progress (student_id, lesson_id, status, completed_at) VALUES (?, ?, 'Completed', NOW())");

    $insert->bind_param("ii", $student_id, $lesson_id);

    $insert->execute();

}

 

echo "Lesson marked as completed!";

?>


💻 /learning/progress_tracker.php
To show learning progress.

<?php

session_start();

$conn = new mysqli("localhost", "root", "", "learning_platform");

$student_id = $_SESSION['user_id'];

 

$query = "SELECT lessons.title, lesson_progress.status FROM lesson_progress

          JOIN lessons ON lessons.id = lesson_progress.lesson_id

          WHERE lesson_progress.student_id = ?";

$stmt = $conn->prepare($query);

$stmt->bind_param("i", $student_id);

$stmt->execute();

$result = $stmt->get_result();

 

echo "<h2>Your Learning Progress</h2><ul>";

while ($row = $result->fetch_assoc()) {

    echo "<li>{$row['title']} - {$row['status']}</li>";

}

echo "</ul>";

?>


💻 /learning/lesson_quiz.php
Display quiz questions.

<?php

$conn = new mysqli("localhost", "root", "", "learning_platform");

$lesson_id = $_GET['lesson_id'];

 

$result = $conn->query("SELECT * FROM quizzes WHERE lesson_id = $lesson_id");

 

echo "<form action='submit_quiz.php' method='POST'>";

while ($row = $result->fetch_assoc()) {

    echo "<h4>{$row['question']}</h4>";

    echo "<input type='radio' name='quiz[{$row['id']}]' value='A'> {$row['option_a']}<br>";

    echo "<input type='radio' name='quiz[{$row['id']}]' value='B'> {$row['option_b']}<br>";

    echo "<input type='radio' name='quiz[{$row['id']}]' value='C'> {$row['option_c']}<br>";

    echo "<input type='radio' name='quiz[{$row['id']}]' value='D'> {$row['option_d']}<br>";

}

echo "<button type='submit'>Submit Quiz</button></form>";

?>


💻 /learning/submit_quiz.php
Handle quiz submission.

<?php

session_start();

$conn = new mysqli("localhost", "root", "", "learning_platform");

$student_id = $_SESSION['user_id'];

 

foreach ($_POST['quiz'] as $quiz_id => $selected_option) {

    // Fetch correct option

    $query = "SELECT correct_option FROM quizzes WHERE id = ?";

    $stmt = $conn->prepare($query);

    $stmt->bind_param("i", $quiz_id);

    $stmt->execute();

    $stmt->bind_result($correct_option);

    $stmt->fetch();

    $stmt->close();

 

    $is_correct = ($selected_option == $correct_option) ? 1 : 0;

 

    $insert = $conn->prepare("INSERT INTO quiz_attempts (student_id, quiz_id, selected_option, is_correct) VALUES (?, ?, ?, ?)");

    $insert->bind_param("iisi", $student_id, $quiz_id, $selected_option, $is_correct);

    $insert->execute();

}

 

echo "Quiz submitted!";

?>


Summary Table

File

Purpose

view_lesson.php

Display lesson content to student

mark_complete.php

Mark the lesson as completed

progress_tracker.php

Show student's progress

lesson_quiz.php

Display quiz for lesson

submit_quiz.php

Handle quiz answers and record attempts

 


Post a Comment

0Comments

Post a Comment (0)