On 28 April 2010 12:29, Juan Rodriguez Monti <juan@xxxxxxxxxxxxxxxxxxxxx> 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > As everyone and their dog has a way ... My loop contains ... $Odd = $Odd ? '' : ' class="odd"'; $Rows .= <<< END_HTML_ROW <tr $Odd> <th>{$RemovalReason->UniqueID}</th> <td>{$RemovalReason->RemovalReason}</td> <td>{$RemovalReason->DateAdded}</td> <td>{$RemovalReason->DateRemoved}</td> </tr> END_HTML_ROW; So, the table has a standard style and odd rows are tagged as odd. This doesn't style the rows directly, just tags the odd rows. Using CSS, you can now construct different styles for odd rows for this table. If you want to have more than 1 table on a page, each with a different style, then fine. Just use appropriate CSS rules. tbody tr { background: url(bg_td1.jpg) repeat-x top; } tbody tr.odd { background: #FFF8E8 url(bg_td2.jpg) repeat-x; } for example, for all normal rows. Add a #ID to that for specific tables, etc. No JS. Minimal html. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php