How to sort data string is alphabet & numeric in PHP?
I have some of the alphabet & numeric string records. I want to sort this all recode DESC and ASC order-wise.
For example,
I have below types of records:
chapter 1
chapter 2
chapter 3
chapter 11
chapter 4
chapter 12
chapter 22
and when I short all recorded that I’m getting this below type of output, but I don’t want this.
chapter 1
chapter 11
chapter 12
chapter 2
chapter 22
chapter 3
chapter 4
but I want the below output.
chapter 1
chapter 2
chapter 3
chapter 4
chapter 11
chapter 12
chapter 22
Add comment
Answers (1)
Add AnswerYou can use “RIGHT( column_name, 3 )” in the MySQL Query. It will work for alphanumeric string sorting.
Please check the below queries for reference.
"SELECT * from table where parent_id='".$portfolio_id."' order by RIGHT( column_name, 3 ) ASC"; "SELECT * from table where parent_id='".$portfolio_id."' order by RIGHT( column_name, 3 ) DESC";
It’s working.
Thank you