Copy link to clipboard
Copied
I got stuck when wanting to display a soccer calendar on a website. There are 30 games per season and I would like every other row to have a light grey background color. Now my question is, is that possible with PHP? I guess it has got something to do with a counter or something.
Below a quick example of how that table would look like with of course the <tr> element getting a repeat region for as many records as there are in the recordset.
Thanks!
<table>
<tr>
<td>Date</td><td>Team 1 vs. Team 2</td><td>Result</td>
</tr>
</table>
Try
...
<table cellpadding="1" cellspacing="3" border="1">
<tr>
<td>Match #</td><td>Date</td><td>Game</td>
</tr>
<?php
$i=0;
do {
$i++;
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
?>
<td><?php echo $row_calendar['day']; ?></td>
<td><?php echo $row_calendar['date']; ?></td>
<td><?php echo $row_calendar['hometeamid']; ?> - <?php echo $row_ca
Copy link to clipboard
Copied
Have a look here http://labs.adobe.com/technologies/spry/samples/data_region/EvenOddRowSample.html
Copy link to clipboard
Copied
So this one you're showing me works with an XML file. Is there a PHP version available as I'm totally not into XML because I don't know anything about that. I use the following code:
<table cellpadding="1" cellspacing="3" border="1">
<tr>
<td>Match #</td><td>Date</td><td>Game</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_calendar['day']; ?></td>
<td><?php echo $row_calendar['date']; ?></td>
<td><?php echo $row_calendar['hometeamid']; ?> - <?php echo $row_calendar['awayteamid']; ?></td>
</tr>
<?php } while ($row_kalender = mysql_fetch_assoc($calendar)); ?>
</table>
Which would output something like the following:
<table cellpadding="1" cellspacing="3" border="1">
<tr>
<td>Match #</td><td>Date</td><td>Game</td>
</tr>
<tr>
<td>1</td>
<td>2010-09-04 11:00:00</td>
<td>5-u12 - 3031-u12</td>
</tr>
<tr>
<td>1</td>
<td>2010-09-04 11:15:00</td>
<td>556-u12 - 79-u12</td>
</tr>
<tr>
<td>1</td>
<td>2010-09-04 12:00:00</td>
<td>1349-u12 - 1434-u12</td>
</tr>
<tr>
<td>1</td>
<td>2010-09-04 13:00:00</td>
<td>5009-u12 - 311-u12</td>
</tr>
<tr>
<td>1</td>
<td>2010-09-04 13:00:00</td>
<td>5661-u12 - 1614-u12</td>
</tr>
</table>
Copy link to clipboard
Copied
Try
<table cellpadding="1" cellspacing="3" border="1">
<tr>
<td>Match #</td><td>Date</td><td>Game</td>
</tr>
<?php
$i=0;
do {
$i++;
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
?>
<td><?php echo $row_calendar['day']; ?></td>
<td><?php echo $row_calendar['date']; ?></td>
<td><?php echo $row_calendar['hometeamid']; ?> - <?php echo $row_calendar['awayteamid']; ?></td>
</tr>
<?php } while ($row_kalender = mysql_fetch_assoc($calendar)); ?>
</table>
Also not the difference in spelling calendar vs kalender
Copy link to clipboard
Copied
When taking your post over, it echoes the following:
Should I copy the <td> cells somewhere in between then?
EDIT: changed the bgcolor to class for convenient sake. Don't think this should influence the output. I'm really sorry for the level of noob'ism 🙂
Copy link to clipboard
Copied
It looks like you have forgotten the <?php and ?> tags.
Having said that, you may be better off keeping your original unformatted table and I shall show you how to convert that table in a SpryHTMLDataSet so that you can use the inbuilt Spry features.
Have you got somewhere to upload your scripts so that you can supply an online URL?
Copy link to clipboard
Copied
So I replaced the opening tag of each row and it works fine now. Like this:
<?php
$i=0;
do {
$i++;
if($i % 2) { //this means if there is a remainder
echo "<tr bgcolor=\"yellow\">";
} else { //if there isn't a remainder we will do the else
echo "<tr bgcolor=\"blue\">";
}
?>
For example, you showed < being the same as <.
Many thanks again vw2ureg!