In the row before every fifth row, the result of the modulo operation will be 4
.. You need to check this in an additional if
statement:
if ($i%5 == 4) {
echo "the next ride is free";
}
Question
I have a table with time entries of taxi rides. I need to list date of rides and every nth ride needs to be free. Thats what i managed to do with this code which shows all rides in table and every 5th is free, counting from first entry:
$c = mysql_num_rows($result);
echo "<table>";
$i=$c;
while ($re = mysql_fetch_array($result)){
$time = $re["time"];
echo "<tr>";
echo "<td>$time</td>";
if ($i != 0 && $i%5 == 0)
echo "<td>Free ride</td>";
$i--;
echo "</tr>";
}
echo "</table>";
Now i need to echo 'Next ride is free' notification when its one ride before free one and echo 'This ride is free' when ride is free. How I can get that one ride from modulus, free one and ride before?
La solution
In the row before every fifth row, the result of the modulo operation will be 4
.. You need to check this in an additional if
statement:
if ($i%5 == 4) {
echo "the next ride is free";
}