divHelper11 divHelper11 - 11 months ago 52
MySQL Question

Numbering the array rows

I have selected the whole table with mysql, there are records of sold tickets.
When I am writing them out with foreach, they are showing correctly from the newest sold ticket at the top to the oldest purchase at the bottom.
The problem is that the IDs do not look good. I have done many test purchases before launching it and the id numbers are starting from 50 now.
I would like to keep it as it is now but only number the records with normal numbers from 1. The problem is that the highest number must be at the top since the latest record is there on top. Could somebody advice me on how to do this please?

Answer Source

When you use while loop you have to create one variable before start loop and increatement it by 1 in loop and use it as row number :)

$sql ="SELECT * FROM  tbl_purchases ORDER BY id DESC";
if ($result = $link->query($sql)) {
    echo "<table border='1'>";
    while($row = mysqli_fetch_assoc($result)) {
        echo "<tr>".
    echo "</table>";