guvenck
12-27-2006, 11:11 PM
I am preparing a comment system. Have no trouble with displaying comments.
$classes = array("blue","red","green","orange","yellow");
include("db.php");
$query = "SELECT ID,title,body,date FROM comments ORDER BY date DESC";
$result = mysql_query($query) or die(mysql_error());
$num_comments = mysql_num_rows($result);
if($num_comments == 0) {
echo '<p>No comments made yet.</p>';
} else {
echo '<p>' . $num_comments . ' comments made.</p>';
$i = 0;
while ($row = mysql_fetch_array($result)) {
echo '<table id="comments" class="' . $classes[$i] .'" cellspacing="0">';
echo '<tr>';
echo '<td valign="top">';
echo '<span>' . $row['title'] . '</span>';
echo '<hr>';
echo '<p>' . $row['body'] . '</p>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<br>';
$i++;
}
}
and external CSS file:
.blue {
background-color: blue;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.orange {
background-color: orange;
}
.yellow {
background-color: yellow;
}
I want the comment tables displayed in different colors and start over again when end of array is reached. In my case, display blue after yellow again.
Any ideas?
$classes = array("blue","red","green","orange","yellow");
include("db.php");
$query = "SELECT ID,title,body,date FROM comments ORDER BY date DESC";
$result = mysql_query($query) or die(mysql_error());
$num_comments = mysql_num_rows($result);
if($num_comments == 0) {
echo '<p>No comments made yet.</p>';
} else {
echo '<p>' . $num_comments . ' comments made.</p>';
$i = 0;
while ($row = mysql_fetch_array($result)) {
echo '<table id="comments" class="' . $classes[$i] .'" cellspacing="0">';
echo '<tr>';
echo '<td valign="top">';
echo '<span>' . $row['title'] . '</span>';
echo '<hr>';
echo '<p>' . $row['body'] . '</p>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<br>';
$i++;
}
}
and external CSS file:
.blue {
background-color: blue;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.orange {
background-color: orange;
}
.yellow {
background-color: yellow;
}
I want the comment tables displayed in different colors and start over again when end of array is reached. In my case, display blue after yellow again.
Any ideas?