0

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);

$lectureStartArray=array('09:00','10:00','11:30','12:30','14:15','15:15');
$weekdays=array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

$subject=array();
$lectureDay=array();
$lectureStart=array();
$i=0;
do{
	  $subject[$i]=$row_schedule['Subject_Name'];
	  $lectureDay[$i]=$row_schedule['Lecture_Day'];
	  $lectureStart[$i]=$row_schedule['Lecture_Start'];
	  $i++;
}while($row_schedule = mysql_fetch_assoc($schedule));
?>


Using these arrays i tried to print subjects as follows:

<table border=1 cellpadding=3>
<tr>
   <td bgcolor="#0099CC"><strong>Hour</strong></td><?php foreach($weekdays as $day) {?>
   <th bgcolor="#FF0066"><strong><?php echo $day;?></strong></th>   
<?php }?>    
</tr>
<?php foreach($lectureStartArray as $val){?>
<tr>
    <td bgcolor="#0099CC"><strong><?php echo $val;?></strong></td><?php foreach($weekdays as $day) {
		$val=$val.':00';	
		 if(in_array($val,$lectureStart)){
			  $i=array_search($val,$lectureStart);	
			  if($day==$lectureDay[$i])	
?>
  	<th bgcolor="#FF99FF"><?php echo $subject[$i];?></th><?php  }
	else?>
    <th bgcolor="#FF9966"></th>
<?php }?>
</tr>
<?php 
}
?>
</table>


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

Attachments timetable.gif 16.22 KB
3
Contributors
7
Replies
18
Views
6 Years
Discussion Span
Last Post by pallavibhoite
0

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>";
$x=1;$y=0;
while(...){
  if(($x - 1)%6 == 0){
     $table .= "<tr><td bgcolor=\"#0099CC\">{$time[$y]}</td>";
     $y++;
  }
  $table .= ($x == $row['cell'])? "<td>..whatever fields..</td>" : "<td>&nbsp;</td>";
  }
  if($x%6 == 0)$table .= "</tr>";
  $x++;
}
$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

0

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.