Order By

This is a discussion on "Order By" within the PHP Forum section. This forum, and the thread "Order By are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 25th, 2007, 21:00
Junior Member
Join Date: Jul 2006
Location: Maine
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Order By

PHP: Select all

$query1 "select * from site_textblocks where text_pid = '3617' ORDER BY headline ASC"
How come when my results sort they do so in this fashion.

1
2
25
3
4
41
5

?
Reply With Quote

  #2 (permalink)  
Old Jun 25th, 2007, 21:56
JustinStudios's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: USA
Posts: 406
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JustinStudios
Re: Order By

because, a computer thinks that is the proper order.

Computers put things in order by the first # and then the 2nd number etc etc. Best way to do this is to put your results into an array and then sort them using sort(array, sort type)
here is a link explaining this: http://www.w3schools.com/php/func_array_sort.asp
Reply With Quote
  #3 (permalink)  
Old Jun 28th, 2007, 13:29
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Order By

You are trying to sort a string field that contains numbers, which means mysql is reading them as text. (In text, 100 comes before 11 for the same reason baa comes before bb.) If you don't want to change the column type, you can convert it to numbers by using
Code: Select all
ORDER BY (headline+0)
This works for me, YMMV.

If you have mixed text and numbers in the field, afaik you're screwed. My solution would be to create a separate varchar field for ordering. Somebody else might have a better solution.

This thread belongs in the MYSQL forum.

Last edited by masonbarge; Jun 28th, 2007 at 13:33.
Reply With Quote
Reply

Tags
sort

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP order form DezMarker PHP Forum 4 Apr 6th, 2008 22:54
save order in the Mysql mcnika Databases 0 Mar 30th, 2008 08:54
help with order for needed bruno89 Web Page Design 21 Oct 1st, 2006 04:38
Tab Order aje Web Page Design 2 May 13th, 2006 14:49
Introductions are in order Anonymous User Introduce Yourself 3 Jun 22nd, 2004 08:25


All times are GMT. The time now is 11:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43