Re: Two color rows in table inside while iteration

From: Date: Thu, 29 Apr 2010 15:53:51 +0000
Subject: Re: Two color rows in table inside while iteration
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-304754@lists.php.net to get a copy of this message
On 4/28/2010 7:29 AM, Juan Rodriguez Monti wrote:
Hello Guys, I would like to implement a two color row table for some queries that I'm doing. I use PHP to query a DB, then I use while to print all its results. I have a code pretty similar to this one : $results = Here the QUERY;
         echo "<html>";
         echo "<head>";
         echo '<link rel="stylesheet" type="text/css" href="style.css" />';
         echo "</head>";
         echo "<body>";
         echo '<div id="container">';
         echo "<center><h2>Results</h2></center><br />";
         echo ("<table border='1'>");
         echo "<td><strong>At1</strong></td>
<td><strong>At2</strong></td>  <td><strong>At3</strong></td>       $
while ($row = while condition )) {
         echo ("<tr>");
         echo "<td>$row[0]</td><td>$row[1]</td>  <td>$row[2]</td>
<td>$row[3]</td><td>$row[4]</td> ";
         echo "</div>";
         echo "</body>";
         echo "</html>";
I just want to show you how I write the table. What I would like to know is what do you suggest to do a two color row format. Thanks!, Juan
$str= "<table>"; $alt = 'even'; foreach(...){ $alt = ($alt == 'odd')?'even':'odd'; $str .= "<tr class=\"$alt\"><td>foo</td></tr>"; // Populate each row; } $str .= "</table>\n"; echo $str;

« previous php.general (#304754) next »