Hi Team
I am looking or finding some ways where on this below code i can use php or jquery to handle select option. Where users can select module of their chose. Kindly please assist, thanks.
Bash
Booking Courses
The courses available for booking or registration by the student.
ping()) {
die("Database connection failed.");
}
// Query to fetch available courses for the logged-in user
$sql = "
SELECT ac.course_id, ac.course_name, ac.duration, ac.category, ac.image
FROM available_courses ac
LEFT JOIN student_modules sm ON ac.course_name = sm.module_name AND sm.student_id = ?
WHERE sm.student_id IS NULL";
// Prepare the SQL statement
$stmt = $conn->prepare($sql);
if (!$stmt) {
die("Error preparing the query: " . $conn->error);
}
// Bind the parameters
$stmt->bind_param("i", $user_id); // Bind the user_id parameter
// Execute the statement
if (!$stmt->execute()) {
die("Error executing the query: " . $stmt->error);
}
// Get the result
$result = $stmt->get_result();
// Check if courses exist for the logged-in user
if ($result->num_rows > 0) {
echo '';
echo '';
echo '';
echo 'Select';
echo 'Image';
echo 'Course Name';
echo 'Duration';
echo 'Category';
echo '';
echo '';
echo '';
while ($row = $result->fetch_assoc()) {
// Convert the image path to a web server relative path
$imagePath = str_replace('C:/xampp/htdocs/', '/', htmlspecialchars($row['image']));
// Debugging: Print image path
echo "Image Path: " . $imagePath . "
";
echo '';
echo '';
echo '';
echo '' . htmlspecialchars($row['course_name']) . '';
echo '' . htmlspecialchars($row['duration']) . '';
echo '' . htmlspecialchars($row['category']) . '';
echo '';
}
echo '';
echo '';
} else {
echo 'No courses available at the moment.
';
}
// Close the statement and the connection
$stmt->close();
$conn->close();
?>
Register
Preview Image
Sangeetha SRank #212 · 11.4K reputationPosted Jan 27, 2025, 4:08 AM EST
Database Connection: The script connects to the database and checks if the user is logged in. If not, it redirects to the login page.
Fetching Courses: It retrieves courses that the logged-in user has not already registered for.
Displaying Courses: It displays the courses in a table format, where each course has a radio button for selection.
Key Points About Checkboxes and Radio Buttons
Radio Button:
Checkbox:
Example Modification for Checkboxes
If you want users to select multiple courses, change your input to checkboxes:
while ($row = $result->fetch_assoc()) { \/\/ Convert the image path to a web server relative path $imagePath = str_replace('C:\/xampp\/htdocs\/', '\/', htmlspecialchars($row['image'])); echo ''; echo ''; \/\/ Change here echo ''; echo '' . htmlspecialchars($row['course_name']) . ''; echo '' . htmlspecialchars($row['duration']) . ''; echo '' . htmlspecialchars($row['category']) . ''; echo ''; }Handling Submission
In your
register_course.php, you'll need to adjust how you handle the submitted data if you switch to checkboxes:if (isset($_POST['course_ids'])) { $selected_courses = $_POST['course_ids']; \/\/ This will be an array of selected course IDs \/\/ Process the selected courses }