简体   繁体   中英

MySQL and PHP Order Addresses by first letter, not numbers

Ok, so I've made a MySQL database for a real estate company, and have it functioning and displaying results. Now I am trying to get the results to show up in ASC order, but when written,

`$query="SELECT * FROM info ORDER BY Address ASC"; `

it sorts by the number in the address, so 100 Zebra Street comes before 200 Apple Way, which I expected. But my desired result is for the query to sort by the first letter in the street name.

Is there an easy way to achieve this, or should I just separate the fields so one column is the number, and the next column is the street name?

Thanks in advance!

I suggest you separate the columns if possible. If you intend to work on parts of the address, then logically you should break it up.

Yes this can be achieved. The solution is outlined here:

stackoverflow.com/questions/3011288/order-by-letters-and-not-numbers-of-a-field

Although it's more practical & efficient to split it into multiple columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM