473,473 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sorting String as Numbers ie (1,100,2) >> (1,2,100)

dlite922
1,584 Recognized Expert Top Contributor
Casting...yes, i know. that's what most of you guys will go for....aaand i'll try it but here's what my data looks like:

10
100D
203(A.b)
203(A.c)
340A
399
500

I'm scared that SOME might even have the letter BEFORE the number

obvious way to do this is with (int) type casting

(for those who have the same problem but without the letters, try that)

Is there a better way than this for my data?

FYI the numbers are in MySQL table, if it can be done query-level, let me also.

Thanks,

DM
Apr 29 '08 #1
1 1259
dlite922
1,584 Recognized Expert Top Contributor
Expected behavior of cast in php according this guy:

http://www.phpf1.com/tutorial/php-string-to-int.html

is
  • "10" -> 10
  • "10.5" -> 10
  • "10,5" -> 10
  • "10 " -> 10
  • " 10 " -> 10
  • "10test" -> 10
  • "test10" -> 0
And come to think of, that behavior is acceptable.

Because, those that start with letters go to the beginning (as they should) if sorted ASC and

203A
203(34)
etc...

will be next to each other in the sort, which gives me a better sort than what i have now.

STILL!! FEEL FREE to give more ideas, its 99% solved for me though.
Apr 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ivo | last post by:
Hi, An array contains elements of the form , for example IVa, XIXb, LIX and LXIVc. Does anyone have a function which can sort this array in a way a human would expect it to, with the roman letters...
1
by: Bern | last post by:
Is it possible to sort 4 integers in either descending/ascending order using ONLY Math.min and Math.max? Cannot use the "if", "while", "for", "switch" keywords.
4
by: balkii | last post by:
hi!!! would appreciate if somebody could let me know the query/algoritham to sort the following values in the column either in asc or desc the values in the column originally 1 1-1/2 1-1/4
3
by: Mars | last post by:
I don't know whether the inputs are all numbers or all strings... if they are numbers, they are sorted as numbers, if they are strings, they are sorted as strings.... e.g. input : 9 12 2...
3
by: John Smith | last post by:
Hello all: New problem. I am currently storing some mostly numeric values as ids in a db but with the possiblity that there are revisions to each. For instance say we have a record such as...
4
by: simchajoy2000 | last post by:
Hi, I've got a datagrid that has columns containing numbers but when the user clicks on the column header to sort - the sort is not placing numbers in the correct order. For example let's say I...
2
by: jodleren | last post by:
Hi! I user sort() but it gives me all uppercase items first. Looking at http://ee.php.net/manual/en/function.sort.php I cannot find what I need - tried natcasesort, but that was even more...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.