Reputation: 1800
In a table I am developing, you can see that there is a person with the best known time. I would like to show it in my page, and so I used this code:
$con=mysqli_connect("localhost","user","pass","database");
if( $result2 = mysqli_query($con,"SELECT playername FROM 1_toad_circuit /*name of the table*/ LIMIT 0 , 30") ) {
$row = mysqli_fetch_row($result2);
printf ("%s \n", $row[0]);
}
As output I am not getting Itoi6 (person with the best time), but I have Catfish (the first in alphabetical order). I have 3 columns as you can see on the picture (link).
I say that I am pretty new with SQL and I would like to know what do I have to fix.
Upvotes: 0
Views: 3332
Reputation: 10841
You need to add an ORDER BY
clause to your statement and then order by whichever field you are storing the times in.
For example, if you had a "time" field:
SELECT playername, time FROM 1_toad_circuit
ORDER BY `time` ASC
LIMIT 1
Upvotes: 1