Mysql and Numbers

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Mysql and Numbers

Post by Mr Tech »

I have this query:

Code: Select all

$query = mysql_query("select * from {$tbl_name}products_items where cat='$cat' order by priority asc");
priority is a number. It can be any number (1, 1.1, 100, 2000.50 etc etc) and it needs to allow me to add dots in the numbers.

When I have priority set to something like INT(10) in phpMyAdmin, it doesn't allow dots. I then changed it to VARCHAR to see if it would allow dots and it did.

However, it did not order the numbers correctly. Instead of ordering it the correct way which is:

1, 50, 100, 200

It ordered incorrectly:

1, 100, 200, 50

How can I make it allow dots but also order correctly?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use a precision type, like FLOAT or DOUBLE


fyi: when strings/characters (like VARCHAR is), the second result is correct.
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks feyd :wink:
Post Reply