Click here to Skip to main content
13,804,051 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");
   = "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";
                    tbl.rows[i].style.backgroundColor = "#ffffff";


<table class="myTable" id="myTable" >
					<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>                                        

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!


1 solution

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

Solution 1

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

$i = 1;
*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*
<?php $i++ ??>

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


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