Page 1 of 1

[S]Can I use date/time in a table to view the latest update?

Posted: Sat Jan 31, 2004 6:44 am
by Braindead)1
I have a mySQL database with in it:
usernames
email-addresses &
date/time

The date/time is altered whenever a user changes his email-adress.
Now I want to use this time/date to make an output to the screen like:

The email-list is <'time/date'> updated.

How can I retrieve, at all times, the latest update date/time??
This date/time needs to change whenever a (random) user alters his email-adress.

Extra info:
The field in MySQL for date/time is called "lastupdate".

Thanx in advance.

Posted: Sat Jan 31, 2004 7:30 am
by timvw
SELECT MAX(lastupdate)
FROM emailadresses
GROUP BY lastupdate


?

Posted: Sat Jan 31, 2004 11:05 am
by Braindead)1
Well, it's official now.
I am a newbe, because I can't get the command to work.

If I only use the command, it will give no output.
I have tried to work with variables, but it just doesn't give the requested output.

Can anyone please help me?

Posted: Sat Jan 31, 2004 11:11 am
by markl999
Try :
SELECT * FROM foo ORDER BY lastupdate DESC LIMIT 1;

Replace * with whatever fields you want to retrieve and foo with your table name.

Posted: Sat Jan 31, 2004 11:30 am
by Braindead)1
Nope, still no result.

I tried:
SELECT lastupdate FROM usermail ORDER BY lastupdate DESC LIMIT 1

inhere, lastupdate is the fieldname and usermail is the tablename.

When I try:
$update = 'SELECT lastupdate FROM usermail ORDER BY lastupdate DESC LIMIT 1';
echo $update;

the result is that the exact text between '' is produced on the screen, not the value from the table.

I get the same result if I put the entire SELECT-command in "".

?????????

I'm puzzled now, because I was tought that information between "" would result into a variable, while between '' the output would be exactly what you put between them.

Posted: Sat Jan 31, 2004 11:33 am
by markl999
Er...yeah...
$update = 'SELECT lastupdate FROM usermail ORDER BY lastupdate DESC LIMIT 1'; won't actually run a query for you, it's just a string..

You want something along the lines of..

Code: Select all

$db = mysql_connect('localhost', 'user', 'password') or die(mysql_error());
mysql_select_db('thedbname') or die(mysql_error());
$query = 'SELECT lastupdate FROM usermail ORDER BY lastupdate DESC LIMIT 1';
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) > 0){
     $row = mysql_fetch_assoc($result);
     echo $row['lastupdate'];
} else {
    echo 'No rows returned!';
}

Posted: Sat Jan 31, 2004 11:37 am
by Braindead)1
Works fantastic!!!

Thanks a lot.

Posted: Mon Feb 02, 2004 12:52 pm
by vijayanand16
Use timestamp d type