PHP syntax - referencing CSS amongst PHP loop code

I have a page here, that uses a bit of PHP to loop a series of checkboxes.

I’ve posted a screenshot here:

http://www.handprintwebdesign.co.uk/gsg_checkboxes/

I have the stripes working, but not the rules for the checkboxes so that they don’t appear with a border in IE.

So I have a couple of rules in my CSS:

.tickbox_odd {
          border: 0;
          background-color:#006;
}
.tickbox_even {
          border: 0;
          background-color: #990000;
}

And at the moment, the code I have looks like:

(the line in bold is the key line)

 
while ($keyword=mysql_fetch_assoc($query)) {
 
 
    //If new category close previous row & display new category
    if ($keyword['Category']!=$current_category) {
        if ($current_category && $column !=1 ) { echo "</tr>\
"; }
        $current_category = $keyword['Category'];
        echo "<tr class=\\"categorycell\\"><td colspan=\\"10\\">$current_category</td></tr>\
";
        $column = 1; $row_type="";
    }
 
 
//Create new row if 1st keyword
    if ($column == 1) {
        $row_type = ($row_type=="odd")?"even":"odd";
        echo "<tr class=\\"".$row_type."\\">";
    }
 
 
    //Display the checkbox
    echo "<td width=\\"2%\\">";
    echo "<input type=\\"checkbox\\" class=\\"tickbox_".$row_type."\\"";
    if (in_array($keyword['ActivityID'],$photokeywords)) { echo " checked"; }
    echo " name=\\"ckbox[".$keyword['ActivityID']."]\\" id=\\"ckbox[".$keyword['ActivityID']."]\\">";
    echo "</td>\
";
 
 
    //Display the Keyword
    echo "<td width=\\"18%\\" align=\\"left\\">".$keyword['Activity']."</td>\
";
 
 
    //Close the row if 5th keyword OR increase column count
    if ($column == 4) { echo "</tr>"; $column = 1; }
    else { $column++; }
}
 
 
if ($column != 1) { echo "</tr>"; }

But that isn’t working - any help with this would be appreciated, just to get this detail tidied up.

Thank you.

Since you didn’t bold any of the lines, I’m going to assume this is the key lines that are not working:

if ($column == 1) {
$row_type = ($row_type=="odd")?"even":"odd";
echo "<tr class=\\"".$row_type."\\">";
}

Simply put, you forgot to prefix tickbox_ in your echo statement.

You did it for the checkbox input type (but I wouldn’t expect that to be very visible)

Sorry, the bold did go AWOL.

Is that line not the alternating rows?

The line I meant to bold was:


echo "<input type=\\"checkbox\\" class=\\"tickbox_".$row_type."\\"";

Just to say I have now resolved this one.

Cool, sorry, I didn’t get as much of a chance as I’d like to look at it (work and life got in the way). What was the issue?

Unless it is especially important that the alternating line colors show up in IE 7 or earlier, this sort of thing is better left to the nth-child psuedo-class.


.tickbox {
          border: 0;
          background-color:#006;
}

tr:nth-child(even) .tickbox {
          background-color: #990000;
}

This way your PHP code doesn’t even have to bother with this task, making it simpler to read and simpler to maintain.

EDIT - corrected the CSS based on the HTML in your example.

As an aside, you really need to learn how to do table-less layouts in CSS. It makes the server side code MUCH easier to read and write. Tables are for tabular data - which your example is not.