Hi xelA
Can you post your updated code and ideally don't forget the code tags.
Purple
Here is my code.
(PHP)
<?php
require_once 'scheduler.php';
include 'generate_date.php';
draw_schedule();
function clear_existing_schedule()
{
//deleting existing contents to avoid duplication
$sql="DELETE FROM roomschedule";
mysql_query($sql);
}
function sechudle_courses()
{
//instantiate a course object
$course=new course();
$roomSchecdule=new roomSchedule();
//getDistinctCourses
$courses=$course->getDistinctCourses();
//deleting existing contents to avoid duplication
clear_existing_schedule();
$start=1;
foreach($courses as $value)
{
$numberOfStudents=$course->getNumberOfStudents($value);
$year_of_study=$course->getYearOfStudy($value);
if($year_of_study%2==1)$morning=1;else $morning=0;
$start=$roomSchecdule->updateRoomSchedule($value,$start,$morning,$number OfStudents);
}
}
function position_courses($time_of_day)
{
$roomSchecdule=new roomSchedule();
$course=new course();
$roomSchecdule->sheduleDays($time_of_day);
$days=$roomSchecdule->printDays($time_of_day);
$max=count($days);
$array_value=0;
$courses=$course->getDistinctCourses();
for($i=0;$i<$max;$i++)
{
$course_code=$days[$i][0];
$day_number=$days[$i][1];
if($day_number>$array_value)
{
$array_value++;
}
$numberOfStudents=$course->getNumberOfStudents($course_code);
$class_room=$roomSchecdule->get_classroom($course_code);
$schedule[$i]['day']=$array_value;
$schedule[$i]['course_code']=$course_code;
$schedule[$i]['room']= $class_room;
$schedule[$i]['number_of_students']=$numberOfStudents;
}
return $schedule;
}
function draw_schedule()
{
sechudle_courses();
for($i=0;$i<=1;$i++)
{
if($i==0)
{
$time_of_day='morning';
echo '<h4>MORNING SESSIONS (09:00HRS)</h4>';
}
else
{
$time_of_day='afternoon';
echo '<h4>AFTERNOON SESSIONS (14:00 HRS)</h4>';
}
$schedule=position_courses($time_of_day);
$x=0;
$z=0;
$temp=0; //a temporary variable for checking if the value of the date is greater or less
echo '<table border="1">';
echo '<tr><th>Day</th><th>Course Code</th><th>Venue</th><th>No of
Students</th><th>Date</th></tr>';
//get the starting date
$date=set_date(7,1,2008,true);
foreach($schedule as $value)
{
$z++;
if($temp!=$value['day'])
{
$temp=$value['day'];
++$x;
if($x==5)
{
$x=0; //reseting the counter to 0
}
}
$day=$date['day'];
$month=$date['month'];
$year=$date['year'];
$day_name=$date['day_name'];
$full_date=$year.'-'.$month.'-'.$day;
if ($z!=1) $date=set_date($date['day'],$date['month'], $date['year'],false);
$sql="UPDATE roomschedule SET date='$full_date' WHERE date='$full_date'";
mysql_query($sql);
echo'<tr><td>'.$day_name.'</td><td>'.$value['course_code'].'</td><td>'.$value['room'].'</td><td>'.$value['number_of_students'].'</td><td>'.$full_date.'</td></tr>';
}
echo '</table>';
}
}
?>