This is a discussion on Using simple PHP alternating color code buy rows ALLWAYS GREEN within the PHP General forums, part of the PHP Programming Forums category; I am using a super simple PHP alternating row color code by my rows are always coming out green. The ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am using a super simple PHP alternating row color code by my rows
are always coming out green. The code is really simple. the value for i is set to zero then each time a row is written the value $bgcolorvar is reset to either yellow or blue. The back ground color for that line is then set to the variable bgcolorvar. The problem is each line displays green. To verify I coded this right I even put in the command to echo the value of bgcolorvar in the first cell of each line. And sure enough it flips between writing blue or yellow in each cell. To confirm that I didnt goof up something else I manually set bgcolor="blue" on the line where I have it set to bgcolor="$bgcolorvar" and sure enough it turned blue. The only way I can get it to change colors is to give the variable a new name of a differnt length. Sometimes when I do that ALL the rows turn to magenta. The real kicker is I tried 3 or 4 differnt scripts for alterntating line color and everyone did the same thing. I am running this on apache 1.39 (I think, well it is the 1.XX version of apache) with the latest non-beta release of php. Any idea what I am doing wrong? <table border="1" cellspacing="0" cellpadding="0"> <tr bgcolor="#003366" class="tableheader"> <td ><div align="center" class="style1">Name</div></td> </tr> <?php $i = 0; ?> <?php do { ?> <?php $bgcolorvar = ($i++ & 1) ? 'yellow' : 'blue'; ?> <tr bgcolor="$bgcolorvar"> <td ><div align="center"><?php echo $bgcolorvar ?><?php echo $row_rsPayments['item_name']; ?> </div></td> <td> <?php } while ($row_rsPayments = mysql_fetch_assoc($rsPayments)); ?> </table> |