alapimba Posted January 20, 2009 Share Posted January 20, 2009 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? Link to comment https://forums.phpfreaks.com/topic/141610-repeat-with-diferent-colors-for-each-line/ Share on other sites More sharing options...
cooldude832 Posted January 20, 2009 Share Posted January 20, 2009 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 ?> Link to comment https://forums.phpfreaks.com/topic/141610-repeat-with-diferent-colors-for-each-line/#findComment-741226 Share on other sites More sharing options...
alapimba Posted January 20, 2009 Author Share Posted January 20, 2009 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 ?> Link to comment https://forums.phpfreaks.com/topic/141610-repeat-with-diferent-colors-for-each-line/#findComment-741321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.