can i use two if statementes in foreach loop?
Posted: Tue Mar 02, 2010 5:28 am
Hi,
i'm interested: how to use two if statements in foreach loop to get different class for table row based on even or odd it is.
but my code doesn't work.
would be very grateful for pointing the mistake.
foreach ($row as $key=>$value){
$x =0;
$id = $value['id'];
$value = unserialize($value['user_data']);
if ($x%2 == 0)
{
print '<tr class="odd">';
}
elseif {
print '<tr>';
}
endif;
if (@array_key_exists('c19_2', $value)) {
echo'<td width="50" style="background:green;">';
print $id;
echo"<td />";
echo'<td width="50" style="background:red;">';
print $value['c19_2'];
echo"<td />";
$x++;
}
echo '</tr>'
}
i'm interested: how to use two if statements in foreach loop to get different class for table row based on even or odd it is.
but my code doesn't work.
would be very grateful for pointing the mistake.
foreach ($row as $key=>$value){
$x =0;
$id = $value['id'];
$value = unserialize($value['user_data']);
if ($x%2 == 0)
{
print '<tr class="odd">';
}
elseif {
print '<tr>';
}
endif;
if (@array_key_exists('c19_2', $value)) {
echo'<td width="50" style="background:green;">';
print $id;
echo"<td />";
echo'<td width="50" style="background:red;">';
print $value['c19_2'];
echo"<td />";
$x++;
}
echo '</tr>'
}