note 17574 deleted from function.is-float by jimw

From: Date: Thu, 20 Dec 2001 23:38:18 +0000
Subject: note 17574 deleted from function.is-float by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23586@lists.php.net to get a copy of this message
I think an even simpler approach to altering background colors in table rows is turning a switch on/off every time you write a row of data. Before writing each row, check your switch. If it is on, use one color, otherwise use the second color. After writing each row of data, turn your switch on/off accordingly. Your switch will be a variable that is initialized to 1. That switch represents one of the two colors. In the example code bellow, the switch represents a particular shade of blue. You turn the switch on/off by multyplying it by -1. Example: <!-- Begin table --> <table> <!-- Table headings --> <tr bgcolor="#ccffff"> <th>App. ID</th> <th>Officer ID:</th> <th>Date</th> <th>Time</th> <th>Borrower</th> <th>Co-Borrower</th> <th>Amount</th> </tr> <?php //Start with your switch on: $bol_bluebg = 1; do { /*Decide which of the two colors you'll use based on the state of your switch:*/ if($bol_bluebg) $str_bgcolor = "#66ccff"; else $str_bgcolor = "#ccffff"; /* Ouput your row, using the selected background color: */ echo "<tr bgcolor=\"$str_bgcolor\">"; //Statements to display row contents go here... echo "</tr>"; //Once you're finished with this row, switch colors: $plbol_bluebg *= -1; } while($dbrow = mysql_fetch_array($sqlresult)); ?> </table> That's much simpler, isn't it?

« previous php.notes (#23586) next »