Mysql
 sql >> Database >  >> RDS >> Mysql

Conversione dei secondi in HH:MM:SS

Usa la funzione MySQL SEC_TO_TIME.

Esempio:

mysql> SELECT SEC_TO_TIME(2378);
        -> '00:39:38'

Quindi puoi scrivere la tua query SQL come:

SELECT username, score, SEC_TO_TIME(timeran) as timetaken FROM gamescores ORDER BY Time DESC

Il tuo codice diventa quindi:

<?php
$result = mysql_query("SELECT username, score, SEC_TO_TIME(timeran) as timetaken FROM gamescores ORDER BY Time DESC");
if (mysql_num_rows($result)) {
for($rank=1; $row = mysql_fetch_assoc($result); $rank++) {
    echo "<tr>
    <td>{$rank}</td>
    <td>{$row['username']}</td>
    <td>{$row['timetaken']}</td>
    <td>{$row['score']}</td>