473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Why does MySQL think that 8:32 is larger than 12:44?

I have a timebased highscore in my flashgame. I send the highscore from flash to database like this 00:00. Then I want to show the highscore with the fastest highscore first.
Expand|Select|Wrap|Line Numbers
  1. ORDER BY time LIMIT 3
  2.  
But I get a result like this:
name 10:22
name 12:44
name 8:32

Why isn't 8:32 at the top?
Mar 3 '11 #1

✓ answered by Rabbit

Because you're storing it as a string. In a string, it does it character by character. So the first character of 10:22 is 1 and the first character of 8:32 is 8. 1 goes before 8. Either store your data as a date/time, an integer, or concatenate a 0 to the beginning of the string if it's 5 characters long.

3 1274
Rabbit
12,516 Expert Mod 8TB
Because you're storing it as a string. In a string, it does it character by character. So the first character of 10:22 is 1 and the first character of 8:32 is 8. 1 goes before 8. Either store your data as a date/time, an integer, or concatenate a 0 to the beginning of the string if it's 5 characters long.
Mar 3 '11 #2
Thank you, just what I needed. There was still a problem, : is not a number. So now I replace : with . before I send it to database, and back again, when it comes back from database.
Mar 4 '11 #3
HaLo2FrEeEk
404 256MB
Convert it to seconds. 8:32 is (8 * 60) + 32 = 512 seconds. When you read it out you can sort it properly then do your conversion back to minutes and seconds on the server side. I was doing the same thing, storing my durations as a string, then I realized that storing it as an unsigned short or int worked better (I'd recommend an unigned short, you'll save 2 bytes per row and the maximum value of an unsigned short is 65,535, which would be 18 hours, 12 minutes, and 15 seconds).

The conversion is simple, here's how I'd do it in PHP:

Expand|Select|Wrap|Line Numbers
  1. $dur = "8:32";
  2. $arr = explode(":", $dur);
  3. $seconds = ($arr[0] * 60) + $arr[1];
You could just run a loop through all of the rows in that table and run an UPDATE query within the loop.
Mar 11 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Tony | last post by:
Can someone a little more clever than I (which means just about anyone on this list) tell me what the implications/benefits are of this are please? ...
2
by: saran | last post by:
I am having a problem with MySQL consuming a lot of memory and eventually throwing an Out of Memory error and restarting itself. The symptoms are that swap usage continues to rise until some...
5
by: Phil Ward | last post by:
The following has recently arose and it is the first time I have noticed this behaviour. I have been using a self-defined string class. It's form is class CMyString { public: ... (no public...
5
by: solitary.wanderer52 | last post by:
I am running PHP5 under Linux. Just a newbie and would like to have it integrated with MySQL. When I execute phpinfo() in a webpage, I see tons of info on php, but nothing on MySQL. Perhaps...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
2
by: geevaa | last post by:
how to copy a database or table in a database to my pen drive? In which path the MYSQL database and tables will be stored? i just wanto insert a new fieldname(column)in my table .. not as the...
16
by: google | last post by:
In a continuous form the following code is under a button in the form header. In Access 2003 and earlier, this goes to a new record, then adds relevant data to that new record. DoCmd.GoToRecord...
4
by: john_smith_nebraska | last post by:
I am using VISTA . I have IIS enabled . I installed VS 2005 successfully. Under old ASPX you knwo you go to inetpub wwwroot and run a test default.aspx file to see if it executes properly....
7
by: Big Moxy | last post by:
Can someone please advise me on how to implement this? The data entered by a user on form 1 on page1.php is posted to delete.php to remove that row from a table. After the SQL operation the user...
7
by: rsk | last post by:
Hi Friends, Can you please explain me what's the menaing of the following statement *((volatile uint *) 0x00450000) = 0x00012345; With Regards, SS..
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.