Forum Moderators: coopster
And what do I need to add to $activities foreach loop to alternate table row colors?
$day = getDay();
foreach ($day as $keyday => $valday){print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
$activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));
$rowCount = 1;
foreach($activities as $key => $valact){
if($valday["dayid"]==$valact["dayid"]){
$time = date('g:i A' , strtotime($valact["time"]));
$bgColor = ($rowCount %2)? 'F2F2F2' : 'CCCCCC';
print("<tr bgColor=$bgColor><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
<td>".$valact["activities"]."</td>
<td>".$valact["venue"]."</td>
<td>".$valact["leader"]."</td>
<td>".$valact["contact"]."</td>
</tr>");
}
}
}
[edited by: coopster at 9:11 pm (utc) on May 11, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]
I assume this colour switch isn't working?
$bgColor = ($rowCount %2)? 'F2F2F2' : 'CCCCCC';
I would think it is because your $rowCount is not incrementing
at the end of the inside loop you need to increment it like so
$rowCount++;
for not showing a day with no activities you would need something to test on the first line of the loop
if (sometest) continue;
I highlighted in bold what I've added.
I added $rowCount++; in, but the row colors aren't alternating properly. See the url I posted in my first post.
I'm not sure what to count for the days with no activities not to show.
$day = getDay();
foreach ($day as $keyday => $valday) {
$activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));
if(count($activities)) {
print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
}
$rowCount = 1;
foreach($activities as $key => $valact) {
if($valday["dayid"]==$valact["dayid"]){
$time = date('g:i A' , strtotime($valact["time"]));
$bgColor = ($rowCount %2)? 'F2F2F2' : 'CCCCCC';
print("<tr bgColor=$bgColor><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
<td>".$valact["activities"]."</td>
<td>".$valact["venue"]."</td>
<td>".$valact["leader"]."</td>
<td>".$valact["contact"]."</td>
</tr>");
}
$rowCount++;
}
}
$day = getDay();
foreach ($day as $keyday => $valday) {
$activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));
$rowCount = 1;
foreach($activities as $key => $valact) {
if(count($valact) && $rowCount == 1) {
print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
}
if($valday["dayid"]==$valact["dayid"]){
$time = date('g:i A' , strtotime($valact["time"]));
$bgColor = (++$rowCount %2)? 'F2F2F2' : 'CCCCCC';
print("<tr bgColor=$bgColor><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
<td>".$valact["activities"]."</td>
<td>".$valact["venue"]."</td>
<td>".$valact["leader"]."</td>
<td>".$valact["contact"]."</td>
</tr>");
}
}
}