shane85 Posted April 1, 2010 Share Posted April 1, 2010 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> Link to comment https://forums.phpfreaks.com/topic/197200-switching-table-background-colors-in-a-functon-help/ Share on other sites More sharing options...
teamatomic Posted April 1, 2010 Share Posted April 1, 2010 Where does $i come from, I dont see print_prospectEntry called at all. So as I see it 0%2==0 so it stays at FFFFFF HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/197200-switching-table-background-colors-in-a-functon-help/#findComment-1035104 Share on other sites More sharing options...
shane85 Posted April 1, 2010 Author Share Posted April 1, 2010 I just included a snipit of the code...before I had this exact same code but the <?php echo findColor($i++); ?> in the table rows and every table row switched colors. Link to comment https://forums.phpfreaks.com/topic/197200-switching-table-background-colors-in-a-functon-help/#findComment-1035106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.