WalksWithSky
Instructor
Hi:
Relatively new to PHP, but am developing an application to access an MySQL database. It's a training app, so I first have it displaying the courses, then when a use clicks on a course, it displays the modules listed in that course under the course name. Then what I would like it to do is when a user clicks on a module under the course name, it lists all the exercises in that module. This is the part that is not working! I thought I could use the same logic for calling the courses and listing the modules for the modules and exercises, but it's not working. Any help would be greatly appreciated!
Here's the code:
Relatively new to PHP, but am developing an application to access an MySQL database. It's a training app, so I first have it displaying the courses, then when a use clicks on a course, it displays the modules listed in that course under the course name. Then what I would like it to do is when a user clicks on a module under the course name, it lists all the exercises in that module. This is the part that is not working! I thought I could use the same logic for calling the courses and listing the modules for the modules and exercises, but it's not working. Any help would be greatly appreciated!
Here's the code:
Code:
<?php
//connect to the database
$conn=mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("safetytrain",$conn) or die(mysql_error());
$display_block = "<h1>Courses:</h1>
<p>Select a course to view its lessons.</p>";
//show courses first
$get_courses="select CourseID, CourseName, CourseDescription from tbl_Courses order by CourseName";
$get_courses_res = mysql_query($get_courses) or die(mysql_error());
if(mysql_num_rows($get_courses_res)<1) {
$display_block.="<p><em>Sorry, there are currently no courses available.</em></p>";
} else {
while ($courses = mysql_fetch_array($get_courses_res)) {
$CourseID = $courses[CourseID];
$CourseName = strtoupper(stripslashes($courses[CourseName]));
$Coursedescription = stripslashes($courses[CourseDescription]);
$display_block.="<p><strong><a href=\"$_SERVER[PHP_SELF]?CourseID=$CourseID\">$CourseName</a></strong>
<br>$Coursedescription</p>";
if($_GET[CourseID] == $CourseID){
//get lessons
$get_lessons = "SELECT ExerciseID, CourseID, ExerciseTitle FROM tbl_Exercises WHERE CourseID = $CourseID";
$get_lessons_res=mysql_query($get_lessons) or die(mysql_error());
if(mysql_num_rows($get_lessons_res)<1) {
$display_block .="<p><em>There are no lessons in this course at this time.</em></p>";
} else {
$display_block .="<ul>";
while($lessons=mysql_fetch_array($get_lessons_res)){
$ExerciseID=$lessons[ExerciseID];
$ExerciseTitle=stripslashes($lessons[ExerciseTitle]);
$display_block.="<li><a href=\"$_SERVER[PHP_SELF]?CourseID=$CourseID?ExerciseID=$ExerciseID\">$ExerciseTitle</a></li>";
}
$display_block .="</ul>";
if($_GET[ExerciseID] == $ExerciseID){
//get exercises
$get_exercises = "SELECT ExerciseStepID, ExerciseID, ExerciseStepNumber, ExerciseStepText FROM tbl_ExerciseSteps WHERE ExerciseID = $ExerciseID";
$get_exercises_res=mysql_query($get_exercises) or die(mysql_error());
if(mysql_num_rows($get_exercises_res)<1) {
$display_block .="<p><em>There are no exercises in this lesson.</em></p>";
} else {
$display_block .="<ul>";
while($exercises=mysql_fetch_array($get_exercises_res)){
$ExerciseStepID=$exercises[ExerciseStepID];
$ExerciseID=$Exercises[ExerciseID];
$ExerciseStepNumber=stripslashes($exercises[ExerciseStepNumber]);
$ExerciseStepText=stripslashes($exercises[ExerciseStepText]);
$display_block .="<li><a href=\"showexercise.php?ExerciseStepID=$ExerciseStepID\">$ExerciseStepText</a></li>";
}
$display_block .="</ul>";
}
}
}
}
}
}
?>
<html>
<head>
</head>
<body>
<?php echo $display_block;?>
</body>
</html>