php - Alphanumeric sorting/ordering from database -


in database, store values of a1, a2, a10, a12, a5, a8 when retrieve out show below:-

a1, a10, a12, a2, a5, a8

is there way sort correctly? like

a1, a2, a5, a8, a10, a12

if string starts single alpha/numeric prefix can use

 select no my_table order substring(no,1,1), substring(no,2)+0  

fiddle here

in php can sort once it's in multidimensional array using usort returning results of strnatcasecmp call on fields.

usort($records, function($a, $b){return strnatcasecmp($a["fieldname"], $b["fieldname"]);}); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -