I'm trying to create a function that alternates table background colors for each row outputted by a MySQL query, but am running into some problems with trying to get the function to distinguish one row from another. I have tried running a simple counter function within a loop, but it has been to no avail:
function counter()
{
$i++;
return $i;
}
echo "<table>";
$query = mysql_query("SELECT * FROM table");
while ($row = mysql_fetch_array($query))
{
$num = counter();
echo "<tr><td>$num</td></tr>";
}
echo "</table>;
My goal is to output "1" as $num for the first row, "2" for the second, and so on. However, with my current code, "1" is outputted for every single row.
Is there any way to increment a function's output?