<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Robert Kern &#187; Tables</title> <atom:link href="http://www.robertkern.com/tags/tables/feed" rel="self" type="application/rss+xml" /><link>http://www.robertkern.com</link> <description>PHP Web developer</description> <lastBuildDate>Tue, 07 Feb 2012 00:34:47 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <cloud
domain='www.robertkern.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <item><title>Use PHP to make alternate coloured rows</title><link>http://www.robertkern.com/php/use-php-to-make-alternate-coloured-rows.html</link> <comments>http://www.robertkern.com/php/use-php-to-make-alternate-coloured-rows.html#comments</comments> <pubDate>Thu, 28 Aug 2008 14:56:39 +0000</pubDate> <dc:creator>Robert Kern</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[Tables]]></category><guid
isPermaLink="false">http://www.robertkern.com/?p=145</guid> <description><![CDATA[I came across an article that described how to use PHP to make alternate coloured rows in a table and was surprised at how difficult they made it.  There is a very simple way to display alternate coloured rows in tabular data.  Read on for more info. Use the following PHP code to display alternate [...]]]></description> <content:encoded><![CDATA[<p>I came across an article that described how to use PHP to make alternate coloured rows in a table and was surprised at how difficult they made it.  There is a very simple way to display alternate coloured rows in tabular data.  Read on for more info.</p><p><span
id="more-145"></span></p><p>Use the following PHP code to display alternate rows in different colours.  What this is actually doing is setting the class for one row to: odd, and the next row to: even.  Then in my css stylesheet I will define .odd and .even to have different background colours.  I see this as a very clean and manageable way to do this common task.</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Set the index to zero</span>
<span style="color: #666666; font-style: italic;">//Put your code here to loop through the database result or whatever it is you are displaying</span>
<span style="color: #666666; font-style: italic;">//Then display the table row</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;tr class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'odd'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'even'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;</pre></div></div><p>This same idea can be used in probably all web development coding languages with slightly different syntax.</p> ]]></content:encoded> <wfw:commentRss>http://www.robertkern.com/php/use-php-to-make-alternate-coloured-rows.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: www.robertkern.com @ 2012-02-07 00:14:40 -->
