View Full Version : Can you use ints at class types for CSS?

Aug 6th, 2009, 06:29 PM
Im currently trying to create a Table which alternates row colors. the function that actually prints the table currently runs as such

function printTable()
echo '<script src = "java_script.js"></script>';
echo '<script src="sorttable.js"></script>';
echo '<table class = "sortable" id = "myTable" border = "1">';
echo '<thead id = "header"><tr>';
foreach($this->columns as $header => $order)
echo '<th>';
echo $header;
echo '</th>';
echo '</tr></thead><tbody>';
$counter = 0;
for($i = 0; $i < $this->numRows; $i++)
echo '<tr onclick = "testChangeRow(this)" onmouseover = "mouseOver(this)" onmouseout = "mouseOut(this)">';
foreach($this->data[$i] as $key => $value)
echo '<td>';
echo $value;
echo '';
echo '</td>';

echo '</tr>';
echo '</tbody></table>';

my idea: have 2 classes: tr.1 and tr.0
take $i%2 (remainder 1 or 0, alternating) and then set

echo '<tr class = 0 (or 1) onclick = "testChangeRow(this)" onmouseover = "mouseOver(this)" onmouseout = "mouseOut(this)">';

however, it seems it will not let me set the class to a int. even if i put it in quotes

echo '<tr class = "0">';

still doesnt work.

is this a css rule? thanks for the help

Aug 6th, 2009, 06:43 PM
Classes and IDs must not start with numbers or special characters, only letters are allowed.
I’m not good at PHP but how about something like:

if(($i%2) == 0) {echo "alt";}

Then you get a string if you have an even or odd row (“alt” stands for “alternate”) that you can insert as class name and style it accordingly.

Aug 6th, 2009, 06:50 PM
thanks idk if im doin it exactly how u said, but either way i got it to work!!