Re: output a table
| From: | Veselina Jecheva | Date: | Wed, 20 Aug 2003 13:57:13 +0000 |
| Subject: | Re: output a table | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-21194@lists.php.net to get a copy of this message | ||
Anthony,
You can use a variable ($i in the example) and increment its value in the while statement.
Then check its value - if its odd or not - this works:-)
Good luck:-))
Veselina
<? $i=0;
while($row = odbc_fetch_row($result))
{ $i++;
?>
<tr>
<td width="22%" align="center" bgcolor="#<? echo $i % 2 ? "F4F4F4" : "ddeeff"; ?>"><font>
<? echo odbc_result($result,5). " ". odbc_result($result,2). " ". odbc_result($result,3)." ".
odbc_result($result,4); ?> </font></td>
<td width="31%" align="center" bgcolor="#<? echo $i % 2 ? "F4F4F4" : "ddeeff"; ?>"><font><? echo odbc_result($result,1); ?> </font></td>
<td width="7%" align="center" bgcolor="#<? echo $i % 2 ? "F4F4F4" : "ddeeff"; ?>"><font><? echo odbc_result($result,6); ?></font></td>
<td width="20%" align="center" bgcolor="#<? echo $i % 2 ? "F4F4F4" : "ddeeff"; ?>"><font><? echo odbc_result($result,7); ?></font></td>
</tr>
<?
}
?>
At 20:36 8/19/03 -0400, Anthony Ritter wrote:
Hi... I'm trying to output a table with alternate background color rows. The following snippet outputs a table after connecting to a mySQL database with posts but all of the rows have the same bgcolor. Any help with the syntax will be greatly appreciated. Thank you. Tony Ritter ........................................ <? <table width=100% cellpadding=3 cellspacing=1 border=1> <tr> <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">AUTHOR</font> </th> <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">POST</font></th> </tr>"; while ($posts_info = mysql_fetch_array($get_posts_res)) {$post_id = $posts_info['post_id']; $post_text = nl2br(stripslashes($posts_info['post_text'])); $post_create_time = $posts_info['fmt_post_create_time']; $post_owner = stripslashes($posts_info['post_owner']);$color1 = "#CCFFCC"; $color2 = "#BFD8BC"; $posts_info = 0; $row_color = ($posts_info % 2) ? $color1 : $color2;//add to display $display_block .= " <tr> <td width=35% valign=topbgcolor=\"$row_color\"><p>$post_owner<br>[$post_create_time]</td><td width=65% valign=top bgcolor=\"$row_color\"><p>$post_text<br><br> <a href=\"replytopost.php?post_id=$post_id\"><strong>REPLY TOPOST</strong></a></td></tr>";} //close up the table $display_block .= "</table>"; ?> -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php