Jump to content

switching table background colors in a functon help


shane85

Recommended Posts

hey guys. So ive created a function that displays a table showing my database records. For every new row, it displays this table with various information. A member from the boards here was kind enough to create a function for me to switch the colors but initially he applied it to rows, I would like to apply it to the table so that for example, the first time the table is shown, for arguement sake the background color would be #FFFFFF and the 2nd time the table is shown, the background color to be #F8F8F8. How do I use this function correctly? Thanks in advance. I have pasted a snipit of the code below. Ive also edited it to what I thought would work, howver, every time the table is repeated it just shows the 1 color and doesnt switch to the next.

 

function findColor($n) {
return ($n % 2 == 0) ? '#FFFFFF' : '#F8F8F8';
}
// Create function to display the news entries
function print_prospectEntry($arrEntry)
{
   // convert \n linebreaks to HTML formatted <br> breaks
   $arrEntry['comments'] = str_replace("\n", '<br>', $arrEntry['comments']);
   $i = 1;
?>


<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color:<?php echo findColor($i++); ?>">
   <tr>
      <td width="10"></td>
      <td width="300">Representative:</td>
      <td style="padding: 5px;">
      <?php echo $arrEntry['representative']; ?>
      </td>
   </tr>
   <tr>
      <td width="10"></td>
      <td width="300">Company Name:</td>
      <td style="padding: 5px;">
      <a href="prospect.php?prospect_id=<?php echo $arrEntry['prospect_id']; ?>"><?php echo $arrEntry['company_name']; ?></a>
      </td>
   </tr>
  <tr>
      <td width="10"></td>
      <td width="300">Phone Number:</td>
      <td style="padding: 5px;">
      <?php echo $arrEntry['phone']; ?>
      </td>
   </tr>
   <tr>
      <td width="10"></td>
      <td width="300">First Name:</td>
      <td style="padding: 5px;"><?php echo $arrEntry['firstname']; ?>
      </td>
   </tr>
   <tr>
      <td width="10"></td>
      <td width="300">Last Name:</td>
      <td style="padding: 5px;">
      <?php echo $arrEntry['lastname']; ?>
      </td>
   </tr>
   <tr>
      <td width="10"></td>
      <td width="300">Last Contacted:</td>
      <td style="padding: 5px;">
      <?php echo $arrEntry['last_contact']; ?>
      </td>
   </tr>
   <tr>
      <td width="10"></td>
      <td width="300">Comments:</td>
      <td style="padding: 5px;">
      <?php echo $arrEntry['comments']; ?>
      </td>
   </tr>
</table>
<br>
<br>

Archived

This topic is now archived and is closed to further replies.

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