Jump to content


Photo

Trouble using MAX() Date


  • Please log in to reply
2 replies to this topic

#1 massive

massive
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 07 March 2006 - 07:31 AM

Hi guyz...its me again heheheh....i was wondering how to view only the recent data by refferring to its date my querying seems to be wrong...

For example:

a customer paid at the date of 2006-03-02...this is the last time he paid....so when i view his information the most recent date would be or should be view "2006-03-02"...not 2006-03-01...not 2006-02-28....etc...

$query = "SELECT * FROM dataz WHERE username = '$username' AND Dated = MAX(Dated) AS most";

"in here i have errors i know my placing of "max(date) as most" is wrong...this comes in handy if i do this"


$query = "SELECT *, MAX(Dated) AS most FROM dataz WHERE username = '$username'";


"i was wondering how could i do this in terms of using WHERE....."

Algorithm: Select everything from dates where this is the user and the date of the user is the most recent...



tnx...^__^

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 07 March 2006 - 07:37 AM

pull them in descending date order

$query = "SELECT * FROM dataz WHERE username = '$username' ORDER BY dated DESC LIMIT 1";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 massive

massive
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 07 March 2006 - 10:47 AM

[!--quoteo(post=352420:date=Mar 7 2006, 02:37 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 7 2006, 02:37 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
pull them in descending date order

$query = "SELECT * FROM dataz WHERE username = '$username' ORDER BY dated DESC LIMIT 1";
[/quote]



Thanks Sir Barand ^____^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users