View Single Post
Old 05-01-2009, 12:57 AM   #2 (permalink)
CrazeD
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,686

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: I need some PHP help! timestamp?

You need to make a new column in your database table as int(11).

Then, when your script inserts the comment, use the PHP time() function as the data for that column.

Then, when you display your column, use the PHP date() function to format the timestamp.

Example:

Insert
PHP Code:
<?php

$name 
$_POST['name'];
$comment $_POST['comment'];

$sql mysql_query ("INSERT INTO comments (id,name,comment,date) VALUES (0,'".$name."','".$comment."','".time()."')");

?>
Display
PHP Code:
<?php

$sql 
mysql_query ("SELECT * FROM comments");

while (
$row mysql_fetch_array ($sql)) {
     echo 
'Name: '.$row['name'].'<br />Comment: '.$row['comment'].'<br />Date: '.date('M/d/Y h:i A'$row['date']);
}

?>
The above would display something like:

Name: My name
Comment: My comment
Date: 05/01/2009 01:30 AM

You can change the way it is formatted by changing the date() parameters. See a list of parameters here.

Hope that helps.
__________________

Need website help? PM me!
CrazeD is offline