?
Solved

Sorting Question using PHP and sql query

Posted on 2011-09-13
3
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

743 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