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

Link to comment
Share on other sites

<?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++
  }
?>

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.