vinpkl Posted January 7, 2009 Share Posted January 7, 2009 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 Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2009 Share Posted January 7, 2009 <?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++ } ?> Quote Link to comment Share on other sites More sharing options...
vinpkl Posted January 7, 2009 Author Share Posted January 7, 2009 <?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 Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2009 Share Posted January 7, 2009 I would look into css for that. Its not what tables where designed for. Quote Link to comment Share on other sites More sharing options...
vinpkl Posted January 7, 2009 Author Share Posted January 7, 2009 I would look into css for that. Its not what tables where designed for. hi thorpe with css u mean to say we should use <div> tag instead. vineet Quote Link to comment Share on other sites More sharing options...
trq Posted January 7, 2009 Share Posted January 7, 2009 Not necessarily, you can apply css stying to table elements. Quote Link to comment Share on other sites More sharing options...
vinpkl Posted January 7, 2009 Author Share Posted January 7, 2009 Not necessarily, you can apply css stying to table elements. right thorpe i got it. vineet Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.