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 Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/ 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++ } ?> Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/#findComment-731367 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 Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/#findComment-731378 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. Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/#findComment-731383 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 Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/#findComment-731388 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. Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/#findComment-731393 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 Link to comment https://forums.phpfreaks.com/topic/139797-solved-change-alternative-rows-background/#findComment-731395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.