Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-02-14, 02:56 PM
Junior Member
 
Join Date: Feb 2006
Posts: 2
sindiglo
Default

Hello,

Can anyone help me with how to get an alphanumeric query result to order correctly.
This is the query I am using right now:

$sql = "SELECT * FROM teams where team_div='B' order by team_num +0";

with this result:

TEAM ID TEAM NAME
C4 (B4) Thrown Together
C6 (B5) Smashers
C1 (B9) Six-Cess
C3 (B10) The Mandelbaums
C5 (B13) Ocelots
C10 (B14) Set To Go
C9 (B15) SpikeVB's
C2 (B16) Serve it Up
C7 (B17) IND B-1
C8 (B18) IND B-2

Any suggestions? (Php4, Mysql 3.51) All fields are text strings.

I was told that if I added the +0 that it would order the list by the Team ID, but it doed not work.

visit http://www.hhmvl.com/c_division.php to see it live!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-02-14, 11:30 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

a text field will not order like that, only a number type field.

Or you can use the various functions like cast() within mysql to break it up and order.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2006-02-15, 10:38 AM
Junior Member
 
Join Date: Feb 2006
Posts: 2
sindiglo
Default

I think I have it!

SELECT * FROM teams where team_div='C' order by SUBSTRING(team_num,2)+0

Substring selects the remaining characters starting at the second. Then I convert the string to an integer by adding 0.

Bingo!

B) B) B)
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

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



All times are GMT -5. The time now is 11:34 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.