View guestbook
<html>
<head>
<title>View guestbook</title>
</head>
<body>
<h3>Latest 3 guestbook entries...</h3>
<?php
$rs = @mysql_connect( "localhost", "userName", "password" )or die( "Could not connect to MySQL" );
$rs = @mysql_select_db( "my_database" ) or die( "Could not select database" );
$sql = "select * from guestbook order by time desc limit 3";
$rs = @mysql_query( $sql ) or die( "Could not execute SQL query" );
while ( $row = mysql_fetch_array( $rs ) )
{
?>
<table>
<tr>
<td><b>Name:</b> <?php echo $row["name"]; ?></td>
<td><b>Email:</b> <a href="mailto:<?php echo $row["email"]; ?>">
<?php echo $row["email"]; ?></a> </td><tr>
<tr><td colspan="2">
<?php
$datetime = $row["time"];
$year = substr( $datetime, 0, 4 );
$mon = substr( $datetime, 4, 2 );
$day = substr( $datetime, 6, 2 );
$hour = substr( $datetime, 8, 2 );
$min = substr( $datetime, 10, 2 );
$sec = substr( $datetime, 12, 2 );
$orgdate = date("l F dS, Y h:i A",mktime( $hour, $min, $sec, $mon, $day, $year ) );
?>
Date: <?php echo $orgdate; ?></td></tr>
<tr><td colspan="2"><b>Comments:</b> <?php echo $row["comments"]; ?></td></tr>
</table>
<br>
<?php } ?>
</body>
</html>
Related examples in the same category