EchoFool Posted October 30, 2010 Share Posted October 30, 2010 Hey, I have a bunch of fields with unusual strings of numbers seperated by symbols (used for php explode stuff at later parts of my script)... But i was wondering if there is a way mysql can order the data even though they are invalid integers/decimals. The values are like this: 5:14:1+3+4+6+7 5:14:1+2+5+6+7 5:13:1+2+3+8+13 But i need them to order by DESC by comparing the numbers going from left to right (in a way - ignoring the : and the + symbols)How is this done? Quote Link to comment https://forums.phpfreaks.com/topic/217282-order-by-customised/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 30, 2010 Share Posted October 30, 2010 You would need to produce a value where the same position in each string has the same significance. That would require that every field making up the value has the same length. You could then directly compare the values as strings (even with the : and + still in them) because each character position in a string has the same significance/magnitude as that same character position in the other string(s). What are the maximum number of possible digits for each number within that data? You are implying 2 (the :13, :14, and +13) Edit: The short answer would be if you were to include leading zero's on each number/field making up the values when they are stored, so that each stored value has the same length/format, you could ORDER BY them directly. Quote Link to comment https://forums.phpfreaks.com/topic/217282-order-by-customised/#findComment-1128321 Share on other sites More sharing options...
EchoFool Posted October 30, 2010 Author Share Posted October 30, 2010 Hey - well the highest number is 14. Okay so adding 01 02 03 etc will solve my problem ? Will give it a try thank you! Quote Link to comment https://forums.phpfreaks.com/topic/217282-order-by-customised/#findComment-1128394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.