<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/1.10.2" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>All Blogs - Last comments</title>
				<link>http://programming.valzubiri.com/blog/index.php?blog=1&#38;disp=comments</link>
		<description></description>
		<language>en-US</language>
		<docs>http://backend.userland.com/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=1.10.2"/>
		<ttl>60</ttl>
				<item>
			<title>In response to: Alternate Colors on MySQL result rows</title>
			<pubDate>Sat, 07 Feb 2009 04:07:20 +0000</pubDate>
			<dc:creator>valzubiri [Member]</dc:creator>
			<guid isPermaLink="false">c1691@http://programming.valzubiri.com/blog/</guid>
			<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>
			<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>
		</item>
				<item>
			<title>In response to: Alternate Colors on MySQL result rows</title>
			<pubDate>Thu, 05 Feb 2009 20:26:00 +0000</pubDate>
			<dc:creator>Jan [Visitor]</dc:creator>
			<guid isPermaLink="false">c1690@http://programming.valzubiri.com/blog/</guid>
			<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>
			<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>
		</item>
			</channel>
</rss>
