Click here to Skip to main content
13,591,539 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hey guys,

I've googled high and low and I can't seem to find any javascript or php code that works with the table on my index.php page. Here's what I have now:

<script language="javascript">
        function setcolor() {
            var tbl = document.getElementById("myTable");
            tbl.style.color = "white";
            tbl.rows[0].style.backgroundColor = "#ffffff";
            for (var i = 1; i < tbl.rows.length; i++) {
                if (i % 2 == 0)
                    tbl.rows[i].style.backgroundColor = "#f4f4f4";
                else
                    tbl.rows[i].style.backgroundColor = "#ffffff";
            }
        }
    </script>

......

<table class="myTable" id="myTable" >
				<tr>
					<td width="85" align="center"><? echo "<font color=#0099FF>" .$recordSet["Driver"] . "</font>"; ?></td>
                                        
					<td width="130" align="center"><? echo "<font color=#0099FF>" .$recordSet["Car"] . "</font>"; ?></td>
                                        
					<td width="40" align="center"><? echo "<font color=#0099FF>" .$recordSet["Time"] . "</font>"; ?></td>
                                        
					<td width="55" align="center"><? echo "<font color=#0099FF>" .$recordSet["Drivetrain"] . "</font>"; ?></td>
                                        
					<td width="15" align="center"><? echo "<font color=#0099FF>" .$recordSet["PP"] . "</font>"; ?></td>
                                        
					<td width="30" align="center"><? echo "<font color=#0099FF>" .$recordSet["Level"] . "</font>"; ?></td>                                        
				</tr>	 				
				</table>


Is there a way to do it directly in php? Or any suggested changes in JS? I'm open to any suggestions. Thanks in advance!


Jerome
Posted 5-Dec-12 10:37am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I found a solution finally, here's the breakdown:

<head>
$i = 1;
?>
</head>
*bunch of html code*
<table class="myTable">
<tr><?php if ($i % 2) echo ' style="background-color: #EBEBEB;"';??>>
				
<td width="85" align="center">" .$recordSet["Driver"] . ""; ?></td>
*more TDs*
</tr>	 				
</table>	
<?php $i++ ??>


It even works with my table class, so I can modify each element independently.


Jerome
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.180618.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100