I have a table I am creating that is a schedule.
Here is the array for the data. Its pretty simple.
[0] is the first room and time for the schedule
[1] is the 2nd room and time for the schedule
[2] is the 3nd room and time for the schedule (rarely used)
$_day1agenda=array();
$_day1agenda[0]=array(
0 =>"8:20");
// KEYNOTE TIME (ex: 8:30)
$_day1agenda[1]=array(
0 =>"8:30",
// 1 =>"",
// 2 =>""
);
// SPEAKER2 TIME - Before Break (ex: 9:15)
$_day1agenda[2]=array(
0 =>"9:15",
// 1 =>"",
// 2 =>""
);
// SPEAKER3 TIME - After Break (ex: 10:30)
$_day1agenda[3]=array(
0 =>"10:30",
// 1 =>"",
// 2 =>""
);
// SPEAKER4 TIME - (ex: 11:00)
$_day1agenda[4]=array(
0 =>"11:00",
// 1 =>"",
// 2 =>""
);
// SPEAKER5 TIME - Before Lunch (ex: 11:30)
$_day1agenda[5]=array(
// 0 =>"",
// 1 =>"",
// 2 =>""
);
// SPEAKER6 TIME - After Lunch (ex: 1:30)
$_day1agenda[6]=array(
0 =>"1:30",
1 =>"1:30",
// 2 =>""
);
// SPEAKER7 TIME - After Lunch (ex: 2:00)
$_day1agenda[7]=array(
0 =>"2:00",
1 =>"2:00",
// 2 =>""
);
// SPEAKER8 TIME - After Lunch (ex: 2:30)
$_day1agenda[8]=array(
0 =>"2:30",
1 =>"2:30",
// 2 =>""
);
// SPEAKER9 TIME - After Afternoon Break (ex: 3:30)
$_day1agenda[9]=array(
0 =>"3:30",
1 =>"3:30",
// 2 =>""
);
// SPEAKER10 TIME - After Afternoon Break (ex: 4:00)
$_day1agenda[10]=array(
0 =>"4:15",
1 =>"4:15",
// 2 =>""
);
// SPEAKER11 TIME - After Afternoon Break (ex: 4:30)
$_day1agenda[11]=array(
// 0 =>"",
// 1 =>"",
// 2 =>""
);
I want this in 1 table, so I did a count() for the rows. (I commented out the rooms not in use because count would have included them in the count function)
$_agendasa=array();
$_agendasa[1] = count($_day1agenda[1]);
$_agendasa[2] = count($_day1agenda[2]);
$_agendasa[3] = count($_day1agenda[3]);
$_agendasa[4] = count($_day1agenda[4]);
$_agendasa[5] = count($_day1agenda[5]);
$_agendasa[6] = count($_day1agenda[6]);
$_agendasa[7] = count($_day1agenda[7]);
$_agendasa[8] = count($_day1agenda[8]);
$_agendasa[9] = count($_day1agenda[9]);
$_agendasa[10] = count($_day1agenda[10]);
$_agendasa[11] = count($_day1agenda[11]);
// MAXIMUM NUMBER OF COLUMNS (ROOMS in USE AT 1 TIME)
$_colmaxday1=max($_agendasa);
In the morning, there is one session in Room1. In the afternoon, there are 2 sessions. Since the agenda for the day may change, I want the table to change. There may be 3 sessions added for the afternoon, for example.
So I set the colspan variables to adjust for up to 4 rooms being used at once:
// SETS COLUMN SPANNING & SPECIAL COLUMNS
// 1 is 1 cell (1 cell for any)
// 2 is 1/2 of the columns (3 or columns total)
// 3 is 1/3 of the columns (2,3 or 4 columns total)
switch ($_colmaxday1) {
case 4;
$_rowspancellsa1=" colspan=\"3\"";
$_rowspancellsa2=" colspan=\"4\"";
$_rowspancellsa3=" colspan=\"6\"";
$_rowspancellsa4=" colspan=\"12\"";
break;
case 3;
$_rowspancellsa1=" colspan=\"2\"";
$_rowspancellsa2="";
$_rowspancellsa3=" colspan=\"3\"";
$_rowspancellsa4=" colspan=\"6\"";
break;
case 2;
$_rowspancellsa1="";
$_rowspancellsa2="";
$_rowspancellsa3="";
$_rowspancellsa4=" colspan=\"2\"";
break;
default:
$_rowspancellsa1="";
$_rowspancellsa2="";
$_rowspancellsa3="";
$_rowspancellsa4="";
break;
}
Lastly is the table output. I have been playing with it and not getting what I want. The sessions in Room 1 in the morning, for example, do not span the 2 columns and instead take up a single cell, thus 1/2 the width of the table.
echo "<table border=1>";
echo "<tr>";
foreach ($_day1agenda as $_day1agendaIndex => $_day1agendaValue) {
foreach ($_day1agendaValue as $_Time => $_TimeValue) {
if ($_agendasa[$_day1agendaIndex]>0) {
if ($_agendasa[$_day1agendaIndex]>=$_colmaxday1) {
$_eqcell=$_agendasa[$_day1agendaIndex];
$_equationcell=(($_agendasa[$_day1agendaIndex]*$_colmaxday1));
// DECIDES WHAT COLSPAN WILL BE
if ($_equationcell===$_colmaxday1*2) {
$_rowspancellday1=$_rowspancellsa4;}
else if ($_equationcell===4) {
$_rowspancellday1=$_rowspancellsa3;}
else if ($_eqcell===4) {
$_rowspancellday1=$_rowspancellsa4;}
else if ($_eqcell===(3)) {
$_rowspancellday1=$_rowspancellsa2;}
else if ($_equationcell===$_colmaxday1) {
$_rowspancellday1=$_rowspancellsa1;}
$_endrow="</td>\n";
} else {$_endrow="</tr>\n<tr>\n"; }
echo "<td".$_rowspancellday1.">";
echo "Col[$_day1agendaIndex]: $_agendasa[$_day1agendaIndex] - $_colmaxday1<br><br><B>EQ Value: $_equationcell\n<br>Time: ";
echo $_TimeValue;
echo $_endrow;
} } echo "</tr>\n<tr>";}
echo "</table>\n";
Attached is the output.
Any help here getting the tables to be dynamic to my needs is appreciated.
Thanks