php实例之显示最新三条留言信息。
代码:
<html> <head> <title>显示留言信息-www.jb200.com</title> </head> <body> <h3>显示最新的三条留言</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>名称:</b> <?php echo $row["name"]; ?></td> <td><b>电子邮箱:</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 ) ); ?> 日期: <?php echo $orgdate; ?></td></tr> <tr><td colspan="2"><b>评论:</b> <?php echo $row["comments"]; ?></td></tr> </table> <br> <?php } ?> </body> </html>