Hey fellas, thanks for reading this :)
I got this script:
<?php
include("db_conn.php"); <- all DB connection info
$sql = "SELECT * FROM users";
$result = mysql_query($sql);
echo '<table>';
while($row = mysql_fetch_object($result)) {
echo "<tr><td>$row->name<td>$row->email<td>$row->status</tr>";
}
echo '</table>';
mysql_free_result($result);
?>
Now i got over 100 or so rows in the users table, and I would like that each time it enters another row in the "while" it will change the color in the <tr>... like in the posts in this forum, first post gets X color and the next one gets Y, then back to X and so on..
How did you guys do that?
<?php
// Load the database connection information.
include("db_conn.php");
$result = mysql_query('
SELECT *
FROM users');
echo '
<table>';
$alternate = true;
while ($row = mysql_fetch_object($result))
{
echo '
<tr style="background-color: ', $alternate ? 'red' : 'blue', '">
<td>', $row->name, '</td>
<td>', $row->email, '</td>
<td>', $row->status, '</td>
</tr>';
$alternate != $alternate;
}
echo '
</table>';
mysql_free_result($result);
?>
-[Unknown]
Thanks buddy :)
Oh hold on, its just putting it as 'Red' all the time... i put the Alternate = true before the while then the Alternate != Alternate in the while and its not changing....
and i fixed it using:
if($alternate == "true") {
$alternate = false;
} else {
$alternate = true;
}
instead of the 2nd one:
$alternate != $alternate;
You should definitely not put "true" in quotes..
-[Unknown]
Ahh.. well, I believe just change
$alternate != $alternate;
to
$alternate = !$alternate;
should work .... or isn't it :-
Oops, see, that was the typo... good eye.
-[Unknown]