[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

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?
0
msvarts
Asked:
msvarts
  • 2
1 Solution
 
msvartsAuthor Commented:
FYI the values 10, 100, 20, 30, 300, 400 are being pulled from the field "order_id"
0
 
Pratima PharandeCommented:
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:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now