Solved

Sorting Question using PHP and sql query

Posted on 2011-09-13
3
212 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress Query 1 35
echo button 13 47
SQL inner join confusion 15 22
Upgrades AWS EC2 & RDS Boxes 1 11
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
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.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now