Jump to content

Need Help MYSQL sort numbers DESC


andyhajime

Recommended Posts

Hey everyone... I'm really stuck. Need help.

 

On mysql_query script (default mode)

 

$FIND = mysql_query("SELECT * FROM listdata WHERE listing_status = '193'");

 

The above line result these numbers below.

- 50.00
- 1200.20
- 46.86
- 843.20
- 10
- 510000

 

 

When I add ORDER BY number DESC, it results this which is totally wrong. I've notice it sorted out based on the first digit instead of as a whole number.

- 843.20
- 510000
- 50.00
- 46.86
- 1200.20
- 10

 

 

The correct result I want is this

- 510000
- 1200.20
- 843.20
- 50.00
- 46.86
- 10

 

Originally on the phpmyadmin table, the data is stored under the type "TEXT".

Tried "VARCHAR(255)", still don't work.

I want to change it to "INT(255)" since I learned that Interger are for numbers but if I changed it, I might risk the data too cause there's decimals in it.

Furthermore I'm working on a LIVE website, so have to be very careful.

 

Any ideas? please help.

Link to comment
https://forums.phpfreaks.com/topic/194607-need-help-mysql-sort-numbers-desc/
Share on other sites

Furthermore I'm working on a LIVE website, so have to be very careful.

You would test and prove any changes on an off line copy of the site/database running on a development system first. You would also have a known good backup copy of the live database before you implement the actual changes on line.

 

What do these numbers represent? What are the expected range of values?

 

Also, INT(11) is the largest integer (you could use a BIGINT if you were only dealing with integer values), but you are correct that using an INT data type would drop the decimal parts. There are FLOAT and DECIMAL data types that would be the correct choice for storing decimal values.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.