Jump to content

% that thingy


forumnz

Recommended Posts

<?php

$color1 = "#FFFFFF";
$color2 = "#000000";

$i=0;

while($i<10) {

if($i % 2 == 0) {
$bgColor = $color1;
} else {
$bgColor = $color2;
}

$i++;

}
?>

 

Obivously replace your while() loop etc, it was just to show how it works.  Aslong as you have something in your loop so you can keep track of the total number of loops, otherwise it won't alternate.

Link to comment
Share on other sites

Thanks,

 

I have this loop:

 

while($row = mysql_fetch_array($result))
  {
  $business_name = $row['business_name'];
  echo "<div id=listingmain>" . $business_name . "</div>";
  }

 

How would I incorporate the 'swapping' into it?

 

I think I would have to do something in the first div? Like:

 

echo "<div id=listingmain style=background-color:#" . $arr . ";>" . $business_name . "</div>";

 

Is that along the right lines?

 

Thanks,

Sam.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.