Plz frenz help me.
I want to display timetable of college lectures using PHP/MySQL.
I stored the information about lectures in Lectures_Info table. It has following fields:
Subject_Name- name of subject,
Lecture_Start-start timing of lecture(like 09:00),
Lecture_Day-Day of lecture(like Monday,Tuesday).

I attached image for the format of timetable.
There are two arrays for lecture start timings and week days.
I am not getting how to display the subject names in corresponding time and days slot.

So far i tried following code:

<?php $query_schedule = "SELECT Subject_Name, Lecture_Day, Lecture_Start FROM lecture_info WHERE Teacher_Id=$tid";
$schedule = mysql_query($query_schedule, $database) or die(mysql_error());
$row_schedule = mysql_fetch_assoc($schedule);


}while($row_schedule = mysql_fetch_assoc($schedule));

Using these arrays i tried to print subjects as follows:

<table border=1 cellpadding=3>
   <td bgcolor="#0099CC"><strong>Hour</strong></td><?php foreach($weekdays as $day) {?>
   <th bgcolor="#FF0066"><strong><?php echo $day;?></strong></th>   
<?php }?>    
<?php foreach($lectureStartArray as $val){?>
    <td bgcolor="#0099CC"><strong><?php echo $val;?></strong></td><?php foreach($weekdays as $day) {
  	<th bgcolor="#FF99FF"><?php echo $subject[$i];?></th><?php  }
    <th bgcolor="#FF9966"></th>
<?php }?>

But there is something wrong with this code. Plz help me.

Attachments timetable.gif 16.22 KB
6 Years
Discussion Span
Last Post by pallavibhoite

I agree, storing day as text is awkward - how about daynumber as Monday = 1...Sat = 6.
Also starttime = 9.00etc - what about period = 1 to 6?

If you store like this, you now have 36 periods per week:

You can check for a calculated field, let's call it CELL which can be calculated thus:

"SELECT `period` + (6*(`day` - 1)) AS `cell`, ... ORDER BY `day`,`period`"

during your while loop:

$time = array('09:00','10:00','11:30','12:30','14:15','15:15');
$table = "<table><tr bgcolor=\"#0099CC\"><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td><td>Saturday</td></tr>";
  if(($x - 1)%6 == 0){
     $table .= "<tr><td bgcolor=\"#0099CC\">{$time[$y]}</td>";
  $table .= ($x == $row['cell'])? "<td>..whatever fields..</td>" : "<td>&nbsp;</td>";
  if($x%6 == 0)$table .= "</tr>";
$table .= "</table>";

Anyway, that's just one way. It's pretty inflexible though, unless you change the no_periods and no_days and reformat.

Edited by diafol: n/a


BTW, I forgot the 'Hour' heading in the table:

$table = "<table><tr bgcolor=\"#0099CC\"><td bgcolor=\"#0099CC\">Hour</td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td><td>Saturday</td></tr>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.