PDA

View Full Version : PHP Guestbook - Retrieving date visitor added comment (MySQL)


Funky Monk
08-11-2004, 08:52 PM
I have a MySQL database that has a field 'date_added'. At the moment I have it set as the type 'timestamp(14)'. I am building a Guestbook and want to display the date and time that the visitor entered their comments.

I DO NOT want the current date. I know how to do that. I can do this with ASP and an Access database, and it takes about 5 minutes. But I'm working on this project in PHP so...

I'm really under pressure in terms of timescales so please make it really simple for me to understand (as much as possible). Thanks.

Hi. I know there are numerous articles on this subject on the Internet but I honestly cannot make sense of it.

sad69
08-11-2004, 09:07 PM
Okay, so the date is already in the database?

So it's just a matter of pulling it out? Here's the gist of it:

$query = 'SELECT date_added FROM table_name WHERE message_id='.$message_id; //select query, message_id narrows result set to 1 row
$result = mysql_query($query, $db); //perform query on database, returns result set into $result
$row = mysql_fetch_assoc($result); //extracts first (and only..) row from $result into $row
echo $row['date_added']; //echo 'date_added' value from $row


That should give you the breakdown if you read the comments..

Sadiq.

raf
08-11-2004, 09:43 PM
you shouldn't use a timestampfield. use a datetime field and set the value with Now() on inserting.
your timestamp will be updated when you update the record so the value then is incorrect.

also, you don't wanna echo the value you pull from the db. you need to transform the timestampvalue into a formatted data, like
date ('j F, Y g:i a' ,strtotime($row['date_added']))