PDA

View Full Version : mySQL ORDER_BY


AaronCampbell
07-09-2004, 05:45 PM
Is there any way to make order_by look at the second line in a field? The database has addresses in it like this:
132 Some Street
SomeCity, ST 99999
The thing is, I want it to order_by city, st. Would have been nice if the db was set up with seperate street_address/city/st/zip columns...

Anyway, in php I do this to the address: $row_info['address'] = preg_split('/\r\n|\n|\r/',$row_info['address']);
then I use $row_info['address'][1] anytime I want the city,st zip line. Is there anyway to make order_by do the same kind of thing?

AaronCampbell
07-09-2004, 06:43 PM
I found a way (not sure if it's right, but it works and that's what matters right now). I pull the info from the table with this:SUBSTRING(address, LOCATE('\r\n', address)+2) as address
then I can order by address, and it works!

scoutt
07-10-2004, 10:50 AM
good job Aaron, I might just use that.