<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/1.10.2" -->
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"					xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel rdf:about="http://programming.valzubiri.com/blog/index.php?blog=1">
	<title>All Blogs - Last comments</title>
	<link>http://programming.valzubiri.com/blog/index.php?blog=1&#38;disp=comments</link>
	<description></description>
	<dc:language>en-US</dc:language>
	<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=1.10.2"/>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
	<items>
		<rdf:Seq>
					<rdf:li rdf:resource="http://programming.valzubiri.com/blog/index.php?blog=2&amp;title=alternate_colors_on_mysql_result_rows&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1#c1691"/>
						<rdf:li rdf:resource="http://programming.valzubiri.com/blog/index.php?blog=2&amp;title=alternate_colors_on_mysql_result_rows&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1#c1690"/>
					</rdf:Seq>
	</items>
</channel>
<item rdf:about="http://programming.valzubiri.com/blog/index.php?blog=2&amp;title=alternate_colors_on_mysql_result_rows&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1#c1691">
	<title>In response to: Alternate Colors on MySQL result rows</title>
	<link>http://programming.valzubiri.com/blog/index.php?blog=2&amp;title=alternate_colors_on_mysql_result_rows&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1#c1691</link>
	<dc:date>2009-02-07T04:07:20Z</dc:date>
	<dc:creator>valzubiri [Member]</dc:creator>
	<description>Here are 2 examples. There are other ways to code, but below is a more simplified way to use the condition on mysql_fetch_object and counting the rows
// $link is your connection to the database
$query = &#34;select * from table where truckcolor='red'&#34;;
$result = mysql_query($query, $link);
$numrows = mysql_num_rows($result);
$i=0;
if ($numrows==0)
&#160;&#160;&#160;{ 
&#160;&#160;&#160;&#160;&#160;&#160;//print nothing... you get the numrows so you 
&#160;&#160;&#160;&#160;&#160;&#160;//can either make a table for the results or not
&#160;&#160;&#160;&#160;&#160;&#160;print(&#34;&#34;);
&#160;&#160;&#160;}
else
&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;&#60;table&#62;&#34;);
&#160;&#160;&#160;&#160;&#160;&#160;while ($row = mysql_fetch_object($result))
&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ($i%3==0)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;row and cell code with the $first color &#34;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ($i%3==1)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;row and cell code with the $second color &#34;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ($i%3==2)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;row and cell code with the $third color &#34;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$i++
&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;&#60;/table&#62;&#34;);
&#160;&#160;&#160;}

Here's another way to use this, given an array

$count = count($thearray);
for ($i=0; $i&#60;$count; $i++)
&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;&#60;table&#62;&#34;);
&#160;&#160;&#160;&#160;&#160;&#160;if ($i%3==0)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;row and cell code with the $first color&#34;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;if ($i%3==1)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;row and cell code with the $second color&#34;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;if ($i%3==2)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;row and cell code with the $third color&#34;);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;print (&#34;&#60;/table&#62;&#34;);
&#160;&#160;&#160;}

If you get the hang of it, you can make more complicated returns.
For example, if you are returning pictures, and you want 5 pictures per row.
Start with $i=5 and increment from there... then divide $i by 5... so if you return $i % 5 == 0, print a tr followed by /tr. Otherwise print cells td /td only... Look at the html of a table and see where codes repeat, and then figure out what I'm talking about :-)
</description>
	<content:encoded><![CDATA[Here are 2 examples. There are other ways to code, but below is a more simplified way to use the condition on mysql_fetch_object and counting the rows<br />
// $link is your connection to the database<br />
$query = &quot;select * from table where truckcolor='red'&quot;;<br />
$result = mysql_query($query, $link);<br />
$numrows = mysql_num_rows($result);<br />
$i=0;<br />
if ($numrows==0)<br />
&nbsp;&nbsp;&nbsp;{ <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//print nothing... you get the numrows so you <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//can either make a table for the results or not<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(&quot;&quot;);<br />
&nbsp;&nbsp;&nbsp;}<br />
else<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;&lt;table&gt;&quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ($row = mysql_fetch_object($result))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($i%3==0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;row and cell code with the $first color &quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($i%3==1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;row and cell code with the $second color &quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($i%3==2)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;row and cell code with the $third color &quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$i++<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;&lt;/table&gt;&quot;);<br />
&nbsp;&nbsp;&nbsp;}<br />
<br />
Here's another way to use this, given an array<br />
<br />
$count = count($thearray);<br />
for ($i=0; $i&lt;$count; $i++)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;&lt;table&gt;&quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($i%3==0)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;row and cell code with the $first color&quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($i%3==1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;row and cell code with the $second color&quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($i%3==2)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;row and cell code with the $third color&quot;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print (&quot;&lt;/table&gt;&quot;);<br />
&nbsp;&nbsp;&nbsp;}<br />
<br />
If you get the hang of it, you can make more complicated returns.<br />
For example, if you are returning pictures, and you want 5 pictures per row.<br />
Start with $i=5 and increment from there... then divide $i by 5... so if you return $i % 5 == 0, print a tr followed by /tr. Otherwise print cells td /td only... Look at the html of a table and see where codes repeat, and then figure out what I'm talking about :-)<br />
]]></content:encoded>
</item>
<item rdf:about="http://programming.valzubiri.com/blog/index.php?blog=2&amp;title=alternate_colors_on_mysql_result_rows&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1#c1690">
	<title>In response to: Alternate Colors on MySQL result rows</title>
	<link>http://programming.valzubiri.com/blog/index.php?blog=2&amp;title=alternate_colors_on_mysql_result_rows&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1#c1690</link>
	<dc:date>2009-02-05T20:26:00Z</dc:date>
	<dc:creator>Jan [Visitor]</dc:creator>
	<description>Hi Val, thanks for that info. However I couldn't get it working with the three colors example.
Could you write some example ?

I had this :

php $i = 0;
php $i++; 

and then :

php if($i&#38;1) { echo 'class="green"';} else {echo 'class="yellow"';}


I didn't follow where to put the "%" sign, or a third statement (I tried an elseif, but didn't work).</description>
	<content:encoded><![CDATA[Hi Val, thanks for that info. However I couldn't get it working with the <strong>three colors example</strong>.<br />
Could you write some example ?<br />
<br />
I had this :<br />
<br />
php $i = 0;<br />
php $i++; <br />
<br />
and then :<br />
<br />
php if($i&amp;1) { echo 'class="green"';} else {echo 'class="yellow"';}<br />
<br />
<br />
I didn't follow where to put the "%" sign, or a third statement (I tried an elseif, but didn't work).]]></content:encoded>
</item>
</rdf:RDF>
