<?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>BIT Consultants &#187; CSS</title>
	<atom:link href="http://www.bitconsultants.net/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitconsultants.net</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 02:19:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Alternating Table Rows with PHP</title>
		<link>http://www.bitconsultants.net/2008/alternating-table-rows-with-php/</link>
		<comments>http://www.bitconsultants.net/2008/alternating-table-rows-with-php/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 05:44:22 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.bitconsultants.net/?p=140</guid>
		<description><![CDATA[Using PHP and CSS, it&#8217;s very easy to create a report-style table with alternating colors on each row. This setup assumes a connection to a MySQL database<a href="http://www.bitconsultants.net/2008/alternating-table-rows-with-php/"> Read More...</a>]]></description>
			<content:encoded><![CDATA[<p>Using <strong>PHP </strong>and <strong>CSS</strong>, it&#8217;s very easy to create a report-style table with alternating colors on each row. This setup assumes a connection to a MySQL database (though any supported DBMS will work), and that you have already queried your database and are ready to work with the results in your php code.</p>
<p>CSS</p>
<pre class="brush: css; title: Code Example; notranslate">
.norm{
color:#fff;
background-color:#000;
}

.alt{
color:#000;
background-color:#fff;
}
</pre>
<p>PHP Code:</p>
<pre class="brush: php; title: Code Example; notranslate">

&lt;?php

$style = 0;//switch to know which row we are on
echo '&lt;table&gt;';
while($row = mysql_fetch_array($query))
{
$name = $row['name'];//for each corresponding column name you wish to show
$add   =  $row['address'];
$email = $row['email'];

if($style == 0)
{
echo '&lt;tr class=&quot;norm&quot;&gt;';
echo '&lt;td&gt;'.$name.'&lt;/td&gt;';
echo '&lt;td&gt;'.$add.'&lt;/td&gt;';
echo '&lt;td&gt;'.$email.'&lt;/td&gt;';
echo '&lt;/tr&gt;';
$style++;
}else{
echo '&lt;tr class=&quot;alt&quot;&gt;';
echo '&lt;td&gt;'.$name.'&lt;/td&gt;';
echo '&lt;td&gt;'.$add.'&lt;/td&gt;';
echo '&lt;td&gt;'.$email.'&lt;/td&gt;';
echo '&lt;/tr&gt;';
$style--;
}
}
echo '&lt;/table&gt;';

?&gt;
</pre>
<p>That&#8217;s all, not much to it really.</p>
<p>Edit: It should be stated that this could be accomplished in a much more simple manner using the ternary operator to conditionally set the class, here is what that would look like:</p>
<pre class="brush: php; title: Code Example; notranslate">

&lt;?php

$style = 'norm';//switch to know which row we are on
echo '&lt;table&gt;';
while($row = mysql_fetch_array($query))
{
$name = $row['name'];//for each corresponding column name you wish to show
$add   =  $row['address'];
$email = $row['email'];
echo '&lt;tr class=&quot;'.$style.'&quot;&gt; ';
echo '&lt;td&gt;'.$name.'&lt;/td&gt;';
echo '&lt;td&gt;'.$add.'&lt;/td&gt;';
echo '&lt;td&gt;'.$email.'&lt;/td&gt;';
echo '&lt;/tr&gt;';
$style = ($style == 'norm') ? 'alt' : 'norm';
}
echo '&lt;/table&gt;';

?&gt;
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.bitconsultants.net/2008/alternating-table-rows-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using xcache
Page Caching using xcache
Object Caching 269/307 objects using memcached

Served from: www.bitconsultants.net @ 2012-02-05 16:03:34 -->
