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 = "select * from table where truckcolor='red'";
$result = mysql_query($query, $link);
$numrows = mysql_num_rows($result);
$i=0;
if ($numrows==0)
{
//print nothing... you get the numrows so you
//can either make a table for the results or not
print("");
}
else
{
print ("<table>");
while ($row = mysql_fetch_object($result))
{
if ($i%3==0)
{
print ("row and cell code with the $first color ");
}
if ($i%3==1)
{
print ("row and cell code with the $second color ");
}
if ($i%3==2)
{
print ("row and cell code with the $third color ");
}
$i++
}
print ("</table>");
}
Here's another way to use this, given an array
$count = count($thearray);
for ($i=0; $i<$count; $i++)
{
print ("<table>");
if ($i%3==0)
{
print ("row and cell code with the $first color");
}
if ($i%3==1)
{
print ("row and cell code with the $second color");
}
if ($i%3==2)
{
print ("row and cell code with the $third color");
}
print ("</table>");
}
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 :-)