Jump to content

[SOLVED] Help with ORDER BY


JSHINER

Recommended Posts

I have the following code:

 

$query = "SELECT * FROM table WHERE var = '$var' ORDER BY name";

 

Which returns results as:

 

Andrew Smith

Bob Jones

Chris Michaels

 

However, I would like it to order by LAST name - so I would like it to be:

 

Bob Jones

Chris Michaels

Andrew Smith

 

I have made the mistake of storing first and last in one field. So I would like to avoid going through and changing everything so there is a field for first name and last name.

 

I was thinking there may be a way to take what is after the last space and have that be $lastname and then ORDER BY '$lastname'

 

Is this possible?

Link to comment
https://forums.phpfreaks.com/topic/50251-solved-help-with-order-by/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.