Sorting Question using PHP and sql query

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?
msvartsAsked:
Who is Participating?
 
Pratima PharandeConnect With a Mentor Commented:
what is datatype of order_id ?

try this

$sql="SELECT * FROM master WHERE mod_id ='bio' ORDER BY Cast (order_id as SIGNED)";
0
 
msvartsAuthor Commented:
FYI the values 10, 100, 20, 30, 300, 400 are being pulled from the field "order_id"
0
 
msvartsAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.