RoosterOahu Posted June 1, 2013 Share Posted June 1, 2013 Hi, How do I alternate the row colors in this code ? <?php include'DB-Connect101'; $id=$_POST['id']; $jobs_sql = "SELECT id,Job_Title,State,DatePostedOn,Company,Island,Job_Category,Oahu_City FROM OahuJobs ORDER BY id DESC"; $jobs_query= mysql_query($jobs_sql) or die (mysql_error); $rsjobs=mysql_fetch_assoc($jobs_query); ?> <table border='0' cellpadding="0" cellspacing="0" width="750:px"> <tr><td colspan="5"><center><font color="green"><center><b>Latest job posting on the Hawaiian Island Of Oahu !</b></center></font></td></tr> <h4> <tr><td colspan="5"><br><br></td></tr> <tr"> <td width="150"><b>Date Posted</b></td> <td width="350"><b>Company</b></td ><td width="120"><b>Job Category</b></td><td><b>Oahu City</b></td> </tr> <tr><td colspan="5"><br><br></td></tr> <?php do {?> <tr> <td> <?php echo date("m/d/Y",strtotime($rsjobs['PostedOnDate'])); ?> </td> <td> <?php echo $rsjobs['Company'];?> </td> <td> <?php echo $rsjobs['Job_Category'];?> </td> <td> <?php echo $rsjobs['Oahu_City'];?> </td> <td><br><br></td> </tr> <tr> <td Colspan="5"> <center><a href="Job-Details.php?id=<?php echo $rsjobs['id'];?>" target="new"><?php echo $rsjobs['Job_Title']; ?></center></a> </td> </tr> <tr><td colspan="5"><br><br></td></tr> <?php } while ($rsjobs=mysql_fetch_assoc($jobs_query)) ?> <tr><td colspan="3"><br><br><br></td></tr> </table> </center> </body> </html> Thanks Link to comment https://forums.phpfreaks.com/topic/278656-alternating-row-colors/ Share on other sites More sharing options...
requinix Posted June 1, 2013 Share Posted June 1, 2013 Make the code work like color = first color do { print using that color color = (color == first color ? second color : first color) } while(...)If you don't like the ternary operator there are plenty of other ways of expressing that kind of toggling logic. Link to comment https://forums.phpfreaks.com/topic/278656-alternating-row-colors/#findComment-1433528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.