Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6340791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:54:11+00:00 2026-05-24T19:54:11+00:00

I found a function to convert seconds to HH:MM:SS online, the function is this:

  • 0

I found a function to convert seconds to HH:MM:SS online, the function is this:

function sec2hms ($sec, $padHours = false) {
$hms = "";
$hours = intval(intval($sec) / 3600);
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. ':';
$minutes = intval(($sec / 60) % 60);
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
$seconds = intval($sec % 60);
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
return $hms;
}

I know this works fine as if I do echo(sec2hms(3600)); it will return as 1:00:00

What I want to happen is to use that function to convert every single entry in the column timeran and then display it in a HTML table with the columns username and score, I am not sure how to do this so if someone could help me out then that’d be great. I am currently using the code below to display the table but that only shows time taken in seconds and I would like it to be in HH:MM:SS:

<tr>
<th>Rank</th>
<th>Username</th>
<th>Time Taken (s)</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php
$result = mysql_query("SELECT * 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>

If there is a better way of converting seconds to HH:MM:SS then that would be great too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:54:11+00:00Added an answer on May 24, 2026 at 7:54 pm

    Use the MySQL SEC_TO_TIME function.

    Example:

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

    So you can write your SQL query as:

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

    Your code then becomes:

    <?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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this website I've found a function to convert seconds in an human readable
Yesterday I found this function: function clone(obj) { return typeof obj === 'undefined' ?
I used the following function I found online and it works perfectly. However, when
So: I have the following function, adapted from a formula found online, which takes
I found this really nice function that receives your desired proportions and resizes/crops the
How to move custom marker to front on google map? I found moveToTop function
I'm learning JQuery and have found the factory function $() with its selectors quite
In the book Programming Collective Intelligence I found the following function to compute the
I found the following code in my team's project: Public Shared Function isRemoteDisconnectMessage(ByRef m
With firebug I found that clicking on the link calls javascript function <a href=#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.