Jump to content

php Switch my Order.. pm not am!!


Gayner

Recommended Posts

ORDER By date_time DESC

 

That's what it is at..

 

and it still shows pm at bottom Here's full query take a look pelase.

 

	$month	=	( isset($_POST[month])	?	$_POST[month]		:	date(F)	);
$year	=	( isset($_POST[year])	?	"20" . $_POST[year]	:	date(Y)	);

 

WHERE receiver_id = '{$ibforums->member["id"]}' && month = '$month' && year = '$year' or sender_id = {$ibforums->member["id"]} && month = '$month' && year = '$year' ORDER By date_time
DESC

 

 

Link to comment
Share on other sites

ORDER By date_time DESC

 

That's what it is at..

 

Then why did you say your code was:

 

ORDER By date_time

 

Try:

 

ORDER By date_time ASC

 

Which is actually the same as the previous statement

 

Lol yea ASC but when people are still on am i dont it to asc.. i want it to DESC like i have.. but when it hit's pm it starts to asc which is my screenshot above.. :(

Link to comment
Share on other sites

Unless your date_time column is an actual mysql DATETIME data type, it won't ORDER BY correctly. What is your table definition?

 

date_time  varchar(250)  latin1_swedish_ci    No  None    Browse distinct values    Change    Drop    Primary    Unique    Index

Link to comment
Share on other sites

I don't know what kind of effort you have been putting into trying to figure it out on your own, but you definitely need to make an increased effort in communicating your problem, here.  Every time someone responds, you respond by giving a little bit more detail.  You will get an answer faster, the more details you give.  just lay all your cards out on the table from the get-go. 

 

Lol yea ASC but when people are still on am i dont it to asc.. i want it to DESC like i have.. but when it hit's pm it starts to asc which is my screenshot above..

 

what does this mean?  Are you saying if there are only "am" dates, you want it to count from earliest time to latest time, but if there there is a "pm" date somewhere in the mix, to order it latest to earliest?  Or only if it's all "pm"?

Link to comment
Share on other sites

You also apparently have month and year columns (probably because you can not do anything with your existing date_time column, except to display it "as is"), along with the date_time column. As awpti posted above, you need to make the column a DATETIME data type. That will eliminate the need for separate month/year columns and all the extra code to populate them because you can test for the month/year of a DATETIME data type directly in a query.

Link to comment
Share on other sites

uh, yes you can ORDER BY a varchar field.  The problem would be that it would sort it alphabetically, and that may or may not coincide with how he has his date/time format. Example:

 

 

This is what he expects the asc to be sorted by, because its in chronological order:

Jan 15th, 2009

Feb 15th, 2009

Mar 15th, 2009

Apr 15th, 2009

May 15th, 2009

Jun 15th, 2009

Jul 15th, 2009

Aug 15th, 2009

Sep 15th, 2009

Oct 15th, 2009

Nov 15th, 2009

Dec 15th, 2009

 

This is what ORDER BY ASC will give him, since it's treated as arbitrary text in a string:

Apr 15th, 2009

Aug 15th, 2009

Dec 15th, 2009

Feb 15th, 2009

Jan 15th, 2009

Jul 15th, 2009

Jun 15th, 2009

Mar 15th, 2009

May 15th, 2009

Nov 15th, 2009

Oct 15th, 2009

Sep 15th, 2009

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.