3
I have a code that displays a table in the ID's
registered, and to decorate, the code makes it display 1 in 1 alternating colors between white and gray.
- COLOR -> White
- COLOR -> Grey
- COLOR -> White
- COLOR -> Grey ...
How can I make a repeat structure while
do the same thing?
<?php
$sqln = mysql_query("SELECT * FROM post ORDER BY id DESC LIMIT ".$inicio.",".$max."");
$num = mysql_num_rows($sqln);
for($i = 0; $i < $num; $i++){
$tituloP = @mysql_result($sqln, $i, "titulo");
$n = $i + 1;
$d = $i % 2;
if($d == 0){$cor = "cinza";}else{$cor = "claro";}
print '<tr class='.$cor.'><td> align="center">'.$tituloP.'</td><tr>';
}
?>
I don’t know if it makes a difference, only now I’m using mysqli
.
<?php
$sqln = mysqli_query($conn, "SELECT * FROM post ORDER BY id DESC LIMIT ".$inicio.",".$max."");
mysqli_close($conn);
while($num_q = mysqli_fetch_array($sqln)){
$tituloP = $num_q['titulo'];
print '<tr class=' /*COR*/'><td align="center">'.$tituloP.'</td><tr>';
}
?>
Do not post source code as image.
– rray
How to change the bottom lines of a table alternately? With support for older browsers
– rray
Thanks for the @rray help, but I’ve already solved the problem with Kup’s answer
– Pedro Quezado