I would like to ask some help. This is not homework but it is just an example on how I want to achieve so I provide example.
Here’s my sample code.
$records = $stmt->prepare("SELECT fname, lname, birthday FROM names ORDER BY birthday DESC");
$records->execute()
foreach($records as $row) {
$birthday = $row['birthday'];
$fname = $row['fname'];
$lname = $row['lname'];
<table>
<tr>
<td>
<?php echo $row['birthday'] . " | " . $row['fname'] . " | " . $row['lname']; ?>
</td>
</tr>
</table>
What I want to achieve is to have a student # before birthday in reverse order.
Student 4 | 1981-11-01 | John | Smith
Student 3 | 1980-11-01 | John | Smith
Student 2 | 1979-11-01 | John | Smith
Student 1 | 1978-11-01 | John | Smith
How can I do that? I have only loop through records and display it but I don’t know how to add Student # in reverse order (old student below and new on top base on birthday)
Thanks a lot.
You should count the number of rows, print and decrement by one