Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.