phillystyle123
asked on
alternate colors with loop using div (not tables)
trying to alternate colors with this loop. absolutely no idea how to do it!
foreach ($results->result as $current) {
echo '<div>';
if ($current->data['phone1']=="") {echo "";} else {echo $current->data['phone1'].'<br/>';}
if ($current->data['dr_url']=="")
{echo $current->data['first_mi'].' '.$current->data['last'].', '.$current->data['title'].'<br/>';}
else
{echo '<a href="'.$current->data['dr_url'].'" target="_blank">'.$current->data['first_mi'].' '.$current->data['last'].', '.$current->data['title'].'</a><br/>';}
if ($current->data['group']=="") {echo "";} else {echo $current->data['group'].'<br/>';}
echo $current->data['address1'].', '.$current->data['address2'].'<br/>';
echo $current->data['city'].', '.$current->data['state'].', '.$current->data['zip'].'<br/>';
printf("%d %s", $current->distance, $units);
echo '</div>';
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops, line:
echo '<div style="color:'.$color.'">' ;
should be as:
echo '<div style="background-color:'. $color.'"> ';
echo '<div style="color:'.$color.'">'
should be as:
echo '<div style="background-color:'.
ASKER
thanks everyone -went with ryancys's solution - much appreciated.
Before the loop:
$x=0;
During the loop:
If ($x % 2 = 0){
// Show code with color 1
}Else {
// Show code with color 2
}
$x++;
End loop