Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When mysql won't sort correctly 1

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
Last in, first to appear is the desire. Yet when I call on the database via php, I get post for May 9, May 8, etc, and after that May 24, May 23, May 21. Something’s wrong.

$query = "SELECT PostID, CONCAT(FName, ' ', SName) AS Name, About, Date_Format(DoA, '%b %e') As DoA FROM Post ORDER BY DoA DESC";
 
Once you do Date_Format, it becomes a string. And gets evaluated as a string. As far as strings go, "May 8" is greater than "May 24". You, for some reason, are aliasing Date_Format(DoA, '%b %e') as an existing column name DoA. I don't think you should do that. Because then you are no longer have access to the original date field to sort by. Try this

Code:
$query = "SELECT  PostID, CONCAT(FName, ' ', SName) AS Name, About, Date_Format(DoA, '%b %e') As DoA1 FROM Post ORDER BY DoA DESC";

That way you sort by the original date string.
 
Of course, azzazzello! Very much obliged to you. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top