the original code is as the following:
<?php
foreach($values as $value){
$downlink=node_load($value);
echo '<li><input type="checkbox" checked="checked"/>.$downlink->title.'</li>';
}
?>
i want to make the output to
<li class="odd">...</li>
<li class="even">...</li>
.....
this is my ways. but it is not work.
$i=0;
foreach($values as $value){
$downlink=node_load($value);
if($i%2==0){
echo '<li class="even"><input type="checkbox" checked="checked"/>.$downlink->title.'</li>';}
else{
echo '<li class="odd"><input type="checkbox" checked="checked"/>.$downlink->title.'</li>';
}
$i++;
}
Your way of doing is perfect but it has a small glitch that might be causing it not to work as intended. It seems you are missing a ‘ (single-quote) after the starting <li> tag after “/>” in both your statements.
This is how it should look (notice the bold single-quote):
echo ‘<li class=”even”><input type=”checkbox” checked=”checked”/>‘ . $downlink->title . ‘</li>’
Another thing though not related – it is not required to put an ending / (forward-slash) at the end of the starting <li> tag because it has it own ending tag </li>