[Pugged] Switch Troubles
Cesar Mendoza
ciapug@ciapug.org
Mon, 24 Mar 2003 16:08:27 -0600
Hi,
I think that your problem is in the "for" loop line, remove the semicolon
(";") at the end of the line. That for loop is doing nothing except setting
$i to the value of $max. That would explain why the value of $last2 never
changes.
Another way to code it would be:
<?php for ($i =0 ;!$result3->EOF; $i++) {
$bgcolor = $i & 1 ? "#e1e1e1" : "#f5f5f5";
<tr bgcolor="<?= $bgcolor ?>">
<td><?= $result3->fields['team_name'] ?></td>
<td><?= $result3->fields['team_position'] ?></td>
<td><?= $result3->fields['team_phone'] ?></td>
<td><?= $result3->fields['team_email'] ?></td>
</tr>
<?php $result3->MoveNext();
} ?>
"$i & 1" is 0 for even numbers and 1 for odd numbers. In base 2, an odd
number always end with 1.
Bye
Cesar Mendoza
http://www.kitiara.org
--
"Hell, n. - The state of being the richest man in
the world and knowing something exists that you can't buy.
Have a kleenex, Bill."
--Black Parrot (Referring to Bill Gates and Linux)
On Mon, Mar 24, 2003 at 02:02:11PM -0500, Chris Van Cleve wrote:
> I wrote the following code to change the background color of every
> other line in a table. For some reason, only the default color is ever
> assigned. Any ideas?
>
> <?php while (!$result3->EOF) {
> for ($i=0; $i < $max; $i++); <-- problem here
> $last2 = $str{strlen($i)-1};
> switch ($last2) {
> case "1":
> case "3":
> case "5":
> case "7":
> case "9":
> $bgcolor = "#e1e1e1";
> break;
> default:
> $bgcolor = "#f5f5f5";
> } ?>
> <tr bgcolor="<?= $bgcolor ?>">
> <td><?= $result3->fields['team_name'] ?></td>
> <td><?= $result3->fields['team_position'] ?></td>
> <td><?= $result3->fields['team_phone'] ?></td>
> <td><?= $result3->fields['team_email'] ?></td>
> </tr>
> <?php $result3->MoveNext();
> } ?>
>
> --
> Chris 'Vanish' Van Cleve
> CEO, President, Founder
> DreamScape Visionery
> _______________________________________________
> Ciapug mailing list
> Ciapug@ciapug.org
> http://cialug.org/mailman/listinfo/ciapug