I am calling a function in PHP that should return values from a database that I have set up. However, I'm getting a blank screen instead of what I'm asking for. If I comment the correct lines out and process it without the function, everything works perfectly. I've posted both examples below- hopefully somebody can notice what's wrong with my function.
Thanks!
This is the code that doesn't work (output is blank):
$month = "9";
$date = "23";
$num_teachers = 2;
$timeslot = "4:00";
$test = date_sched($timeslot);
print($test);
function date_sched($slot) {
for($teacher_col = 1; $teacher_col <= $num_teachers; $teacher_col++) {
$query_student_id = mysql_query("SELECT student_id FROM lesson_details WHERE teacher_id='$teacher_id[$teacher_col]' AND month='$month' AND date='$date' AND time='$slot'");
if (mysql_num_rows($query_student_id) > 0) {
$student_id = mysql_result($query_student_id,0);
$query_student_name = mysql_query("SELECT name FROM students WHERE id='$student_id'");
$student_name = mysql_result($query_student_name,0);
$cell = $cell."<td><a href='main.php?page=man_other&manage=students&student_id=$student_id'>$student_name</a></td>";
} else {
$cell = $cell."<td> </td>";
}
}
return $cell;
}
This is the code that does work:
$month = "9";
$date = "23";
$num_teachers = 2;
$slot = "4:00";
for($teacher_col = 1; $teacher_col <= $num_teachers; $teacher_col++) {
$query_student_id = mysql_query("SELECT student_id FROM lesson_details WHERE teacher_id='$teacher_id[$teacher_col]' AND month='$month' AND date='$date' AND time='$slot'");
if (mysql_num_rows($query_student_id) > 0) {
$student_id = mysql_result($query_student_id,0);
$query_student_name = mysql_query("SELECT name FROM students WHERE id='$student_id'");
$student_name = mysql_result($query_student_name,0);
$cell = $cell."<td><a href='main.php?page=man_other&manage=students&student_id=$student_id'>$student_name</a></td>";
} else {
$cell = $cell."<td> </td>";
}
}
print($cell);
Output for code that does work (copied from page Source Code):
<td><a href='main.php?page=man_other&manage=students&student_id=4'>John Smith</a></td><td> </td>