Jump to content

[SOLVED] change alternative rows background


vinpkl

Recommended Posts

hi all

 

i need to make my every alternative row means 2nd 4th 6th 8th result row background grey. I using the below loop which displays the result.

 

but how can i make rows background different.

 

<?php

$qry="select * from testimonials";

$result=mysql_query($qry);

while($row = mysql_fetch_array($result))

{

$testimonial=$row['testimonial'];

echo "<table>";

echo "<tr>";

echo "<td width=100%>". $testimonial . "</td>";

echo "</tr>";

echo "</table>";

}

?>

 

vineet

<?php
  $qry="select * from testimonials";
  $result=mysql_query($qry);
  $i = 0;
  while($row = mysql_fetch_array($result)) {
    $testimonial=$row['testimonial'];
    echo "<table>";
    echo "<tr>";
    echo (($i % 2) ? "<td width='100%' id='white'>" : "<td width='100%' id='grey'>") . $testimonial . "</td>";
    echo "</tr>";
    echo "</table>";
    $i++
  }
?>

<?php
  $qry="select * from testimonials";
  $result=mysql_query($qry);
  $i = 0;
  while($row = mysql_fetch_array($result)) {
    $testimonial=$row['testimonial'];
    echo "<table>";
    echo "<tr>";
    echo (($i % 2) ? "<td width='100%' id='white'>" : "<td width='100%' id='grey'>") . $testimonial . "</td>";
    echo "</tr>";
    echo "</table>";
    $i++
  }
?>

 

hi thorpe

 

thanks.

 

its works perfect.

 

can u make this line little simple. like i want to add a new blank row after every row to give some spacing. where should i add.

 

echo (($i % 2) ? "<td width='100%' id='white'>" : "<td width='100%' id='grey'>") . $testimonial . "</td>";

 

vineet

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.