473,581 Members | 2,786 Online
Bytes | Software Development & Data Engineering Community
+ 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 1275
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
4597
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 treated as their numerical values? I don't think this is a especially problematic thing to do, but I don't want to re-invent the wheel. Thanks Ivo
1
3247
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
1909
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
1543
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 4 output : 2 4 9 12
3
1558
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 100, a revision may need to be added such as 100a. As a result this column in the db must be set to a string data type. However, when I do so the...
4
10547
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 have the following column of number data: 1 2 3
2
1512
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 interesting.... sort gives me (yes, I am aware of the spelling error) Doc manager
0
8157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6564
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2309
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 we have to send another system
0
1145
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.