petak, 11. ožujka 2011.

PHP, mysql, html, css and coloring every other row

I stumbled upon interesting problem, where I wanted to color every second column with specific color.
Problem was that I had css defined, so the php code did not work correctly:

if (($i % 2)==0) { echo '<tr BGCOLOR="#99CCFF" >'; } else { echo '<tr BGCOLOR="#FFFFFF" >'; };


so I changed it to something like this:

if (($i % 2)==0) { echo '<tr style="background-color:blue" >'; } else { echo '<tr style="background-color:white" >'; }; 

And it works :)

I am also posting here whole example:


$query2="SELECT * FROM participant,submitted,section,status_work WHERE submitted.id_section=section.id_section AND submitted.id_status=status_work.id_status AND participant.id_part=submitted.id_participant";
$result2=mysql_query($query2);
$num2=mysql_num_rows($result2);
if ($num2>0){
echo '<table class="X1">';
for ($i=0;$i<$num2;$i++){
if (($i % 2)==0) { echo '<tr style="background-color:blue" >'; } else { echo '<tr style="background-color:white" >'; };
echo "<td>".($i+1)."</td>";
echo "<td>".mysql_result($result2, $i, 'first')." ".mysql_result($result2, $i, 'last')."</td>";
echo "<td>".mysql_result($result2, $i, 'section.value')."</td>";
echo "</tr>"; }
echo "</table>";
}

Nema komentara:

Objavi komentar