PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
i am working making the colors alternate on each row of output from a query, but have not nailed it. i know comming from a coldfusion (ouch) background that it would be iif mod. any ideas with php? (ignore the db connection information i am working off of memory and i need a bit more programming to get it down)
<?php
$dbi = (database = yadayada, user=postgres);
$sql = $pg_connect($dbi, "select * from testtable");
$rows = $pg_fetchrow($sql);
//here is the area ignore the above, doing it off memory
for ($i=0;$i<$rows;$i++) {
echo "<table><tr><td> test output </td></tr>";
// this is where the alternating colors should be
echo "<tr bgcolor = #DDDDDD>
// rest of code here
?>
any ideas on where to start??!?
thanx for any sugestions!
soshea
here's an example of something I used like that. I declared 2 color variables that hold the color string i want to use for the alternating rows.
$color_var = "color".($i % 2 + 1) builds a string that when $i is odd will evaluate to "color2" and when even "color1" the % operator gets the remainder from integer division.
${$color_var} builds the variable name to use for the rows color.