...

View Full Version : Resolved Echoing results with differing background colors?



greens85
10-26-2009, 05:54 PM
Hi all,

I'm currently echoing some results in a while statement:



<?php
$query = "SELECT * FROM teachingagencies_directory WHERE agencyname LIKE '%$agencyname%' AND region LIKE '%$region%' AND address LIKE '%$city%' AND address LIKE '%$postcode%' $limit";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array ($result)) {
?>
<a href="agencydetails.php?Name=<?php echo $row['agencyname'];?>"><?php echo $row['agencyname'];?></a>
<?php
echo '<br/>';
echo '<br/>';
echo 'Address:'.' '.'<span class="normalfont">'.$row['address'].'</span>';
echo '<br/>';
echo 'Telephone:'.' '.'<span class="normalfont">'.$row['telephone'].'</span>';
echo '<br/>';?>
Website: <span class="normalfont"><a href="<?php echo $row['website']?>"><?php echo $row['website'];?></a></span>
<?php
echo '<br/>';
echo '<br/>';
}


What I'm trying to achieve is giving every other result a light grey background color... but all I can manage is to give all results a light grey background color.

Can anyone advise?

Thanks

er4o
10-26-2009, 06:03 PM
Something like this? :)



$query = "SELECT * FROM teachingagencies_directory WHERE agencyname LIKE '%$agencyname%' AND region LIKE '%$region%' AND address LIKE '%$city%' AND address LIKE '%$postcode%' $limit";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array ($result)) {
$i++;
if ($i & 1) {
echo "
<div style='background-color: #ffffff;'>
<a href='agencydetails.php?Name=" . $row['agencyname'] . "'>" . $row['agencyname'] . "</a>
<br/>
<br/>
Address: <span class='normalfont'>" . $row['address'] . "</span>
<br/>
Telephone: <span class='normalfont'>" . $row['telephone'] . "</span>
<br/>
Website: <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span>
<br/>
<br/>
</div>";
}
else {
echo "
<div style='background-color: #e6e6e6;'>
<a href='agencydetails.php?Name=" . $row['agencyname'] . "'>" . $row['agencyname'] . "</a>
<br/>
<br/>
Address: <span class='normalfont'>" . $row['address'] . "</span>
<br/>
Telephone: <span class='normalfont'>" . $row['telephone'] . "</span>
<br/>
Website: <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span>
<br/>
<br/>
</div>";
}
}

greens85
10-26-2009, 06:18 PM
er40... thats perfect.... just need to move it into css so I can make the page valid!

Thanks

er4o
10-26-2009, 10:22 PM
In your css:


.color1 { background-color: #ffffff; }
.color2 { background-color: #e6e6e6; }


and the div's:



<div class='color1'>
...
<div class='color2'>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum