The value for $i in the code below is always 2. It seems it increments to the first time, but only that time. Any thoughts?
foreach ($records as $row){
$i = 1;
$i++
if ($i % 2 != 0){
$trClass = 'odd';
}else{
$trClass = 'even';
}
echo '<tr class="' . $trClass . '"><td>' .
anchor("admin/delete/$row->id", 'delete') . '</td><td>' .
anchor("admin/edit/$row->id", 'Edit') . '</td>';
foreach ($row as $key => $value){
echo '<td>' . $value . '</td>';
}
echo '</tr>';
$i++;
}
You’re reassigning it to
1every time through the loop. Initialize it outside the loop instead.Also I see that you’re incrementing both at the beginning of the loop and at the end. I assume you only want to do it once (probably keep only the one at the end; remove the one at the beginning).