Solved

Sorting Question using PHP and sql query

Posted on 2011-09-13
3
214 Views
Last Modified: 2012-06-21
The code below sorts properly but cannot distinguish between 10 and 100?

$sql="SELECT * FROM master WHERE mod_id ='bio' ORDER BY order_id";

it sorts: 10, 100, 20, 30, 300, 400

INSTEAD I want in to sort: 10, 20, 30, 100, 300, 400

What do I need to add to the query for it to recognize the difference between 10, 100, 1000 AND SO ON?
0
Comment
Question by:msvarts
  • 2
3 Comments
 

Author Comment

by:msvarts
ID: 36534087
FYI the values 10, 100, 20, 30, 300, 400 are being pulled from the field "order_id"
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 36534097
what is datatype of order_id ?

try this

$sql="SELECT * FROM master WHERE mod_id ='bio' ORDER BY Cast (order_id as SIGNED)";
0
 

Author Closing Comment

by:msvarts
ID: 36534104
what is datatype of order_id ?

Sorry I am a newbie. This observation was key as it was a VARCHAR - I changed it to SMALLINT and everything works fine - THANK YOU...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question