Редуване на цветовете в таблица

akatsuki

Registered
Здравейте. Искам да направя нещо като това : http://www.onemanga.com/directory/ Като изкарва от базата данни резултатите да се редуват. Как ще стане това? Ето го кода, на който искам да вградя това.. :
Код:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "config.php";
$result = mysql_query("SELECT * FROM manga ORDER BY id DESC") or die (mysql_error());
echo "
<table width='590' style='margin-left:15px;'>
<tr style='background:#eee; color:#000; font-family:arial; font-weight:bold;'>
<th style='width:200px;'>Име:</td>
<th style='width:200px;'>Последен:</td>
<th style='width:190px;'>Автор:</td>
</tr>
";
while($data = mysql_fetch_assoc($result)) {
echo "<tr style='background:#f7f6f6; color:#000; font-family:arial;'>
<td id='name'><a href='#'>$data[name]</a></td>
<td>bla bla</td>
<td>$data[avtor]</td>
</tr>";
}
echo "</table>";
?>
 
Код:
<?
include "config.php";
$result = mysql_query("SELECT * FROM manga ORDER BY id DESC") or die (mysql_error());
echo "
<table width='590' style='margin-left:15px;'>
<tr style='background:#eee; color:#000; font-family:arial; font-weight:bold;'>
<th style='width:200px;'>Име:</td>
<th style='width:200px;'>Последен:</td>
<th style='width:190px;'>Автор:</td>
</tr>
";
while($data = mysql_fetch_assoc($result)) {
$name = $data['name'];
$avtor = $data['avtor'];
if ($alternate == '1') {
$color = "#c0c0c0";
$alternate = "2";
}
else {
$color = "#fff";
$alternate = "1";
}
echo "<tr style='background:$color; color:#000; font-family:arial;'>
<td id='name'><a href='#'>$name</a></td>
<td>bla bla</td>
<td>$avtor</td>
</tr>";
}
echo "</table>";
?>

Пробвай така..
 
Код:
	 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "config.php";
$result = mysql_query("SELECT * FROM manga ORDER BY id DESC") or die (mysql_error());
echo "
<table width='590' style='margin-left:15px;'>
<tr style='background:#eee; color:#000; font-family:arial; font-weight:bold;'>
<th style='width:200px;'>Име:</td>
<th style='width:200px;'>Последен:</td>
<th style='width:190px;'>Автор:</td>
</tr>
";
$i = 0;
while($data = mysql_fetch_assoc($result)) {
if ($i % 2){
  $colort = "#fff";
}else{
  $colort = "#c0c0c0";
}
echo "<tr style='background:".$colort."; color:#000; font-family:arial;'>
<td id='name'><a href='#'>$data[name]</a></td>
<td>bla bla</td>
<td>$data[avtor]</td>
</tr>";
$i++;
}
echo "</table>";
?>
 

Back
Горе