Jump to content

repeat with diferent colors for each line


alapimba

Recommended Posts

Hello, i wrote a script to repeat some regions on my site.

 

But i wanted each region in one diferent color, i just don't know how to do that, anyone can help?

 

My code:

<?php 
$x = -1;
$first = 0; // 1a coluna
while ($row_rs_conteudo = mysql_fetch_assoc($rs_conteudo)) { 
	if($x != $row_rs_conteudo['titulo_id']){ //se e 1 livro novo
		$x = $row_rs_conteudo['titulo_id']; 
		if($first != 0){ // se nao e a 1a coluna
	echo "</td></tr>"; //final da coluna
	} else {
		$first = 1;
		}
?>
<tr><td width="180" valign="top">
<span class="style4"><?php echo $row_rs_conteudo['titulo']; ?> </span> <br>
<?php } ?>
<a href="#">·</a> <span class="style8"><?php echo $row_rs_conteudo['sub_titulo']; ?></span> <br>
<?php
}
echo "</td>"; //fim da tabela
echo "</tr>"; //fim da tabela
?>

 

The part that i want each line in a diferent color is:

 

<span class="style4"><?php echo $row_rs_conteudo['titulo']; ?> </span>

 

I wanted the first loop to use style4 the second style5 the third style6 the fourth style 7 and so on..

How can i do that?

 

Try adding in a $i to count up as you go  (check the file output to verify)

<?php 
   $i = 1;
   $x = -1;
   $first = 0; // 1a coluna
   while ($row_rs_conteudo = mysql_fetch_assoc($rs_conteudo)) { 
      if($x != $row_rs_conteudo['titulo_id']){ //se e 1 livro novo
         $x = $row_rs_conteudo['titulo_id']; 
         if($first != 0){ // se nao e a 1a coluna
      echo "</td></tr>"; //final da coluna
      } else {
         $first = 1;
         }
?>
   <tr><td width="180" valign="top">
   <span class="style<?php echo $i;?>"><?php echo $row_rs_conteudo['titulo']; ?> </span> <br>
<?php 
$i++;
} ?>
<a href="#">·</a> <span class="style8"><?php echo $row_rs_conteudo['sub_titulo']; ?></span> <br>
<?php
}
echo "</td>"; //fim da tabela
echo "</tr>"; //fim da tabela
?>

well i complicated a little bit but solved basicly the same way.

 

thanks for your tip.

 

here is the result in case anyone else needs.

 

<?php 
$x = -1;
$first = 0; // 1a coluna
$cntr = 1;
while ($row_rs_conteudo = mysql_fetch_assoc($rs_conteudo)) { 
	if($x != $row_rs_conteudo['titulo_id']){ //se e 1 livro novo
		$x = $row_rs_conteudo['titulo_id']; 
		if($first != 0){ // se nao e a 1a coluna
	echo "</td></tr>"; //final da coluna
	} else {
		$first = 1;
		}
		switch ($cntr) {
        case 1:
            $cssClass = "style3";
		break;
        case 2:
            $cssClass = "style4";
		break;
        case 3:
            $cssClass = "style5";
		break;
	case 4:
            $cssClass = "style6";
		break;
	case 5:
            $cssClass = "style7";
		break;
    } 
$cntr++;
?>
  <tr>
    <td width="180" valign="top"><span class="<?php echo $cssClass ?>"><?php echo $row_rs_conteudo['titulo']; ?></span> <br />
      <?php } ?>
      <a href="#">·</a> <span class="style8"><a href="energia_content.php?id=<?php echo $row_rs_conteudo['id_conteudo']; ?>"><?php echo $row_rs_conteudo['sub_titulo']; ?></a></span> <br />
      <?php
}
echo "</td>"; //fim da tabela
echo "</tr>"; //fim da tabela
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.