Jump to content

Recommended Posts

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

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