现在的位置: 首页php实例>正文
guestbook的查看留言功能  
发表于542 天前 php实例 评论关闭

根据功能设计,php中guestbook的查看留言功能是对postsmysql数据表进行操作。

guestbook的查看留言功能因为只需要查询审核过的,所以只是对mysql数据表进行查询操作,并且为了查看的方便需要倒序排序。

php代码如下:

<!-- 查看留言 -->
<?php require_once('Connections/conn.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rs = 10;
$pageNum_rs = 0;
if (isset($_GET['pageNum_rs'])) {
$pageNum_rs = $_GET['pageNum_rs'];
}
$startRow_rs = $pageNum_rs * $maxRows_rs;

mysql_select_db($database_conn, $conn);
$query_rs = "SELECT * FROM posts WHERE checked=1 ORDER BY postid DESC";
$query_limit_rs = sprintf("%s LIMIT %d, %d", $query_rs, $startRow_rs, $maxRows_rs);
$rs = mysql_query($query_limit_rs, $conn) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);

if (isset($_GET['totalRows_rs'])) {
$totalRows_rs = $_GET['totalRows_rs'];
} else {
$all_rs = mysql_query($query_rs);
$totalRows_rs = mysql_num_rows($all_rs);
}
$totalPages_rs = ceil($totalRows_rs/$maxRows_rs)-1;

$queryString_rs = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rs") == false &&
stristr($param, "totalRows_rs") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rs = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rs = sprintf("&totalRows_rs=%d%s", $totalRows_rs, $queryString_rs);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.style1 {
font-size: 18px;
font-weight: bold;
}
.style2 {font-size: 14px}
-->
</style>
</head>

<body>
<p align="center" class="style1">留言板 - 留言浏览</p>
<p align="center" class="style2"><a href="newpost.php">发表留言</a> | <a href="admin.php">管理登陆</a></p>
<?php do { ?>
<table width="500" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="116"><div align="right"><strong>用户名:</strong></div></td>
<td width="378"><?php echo $row_rs['username']; ?></td>
</tr>
<tr>
<td><div align="right"><strong>标题:</strong></div></td>
<td><?php echo $row_rs['topic']; ?></td>
</tr>
<tr>
<td><div align="right"><strong>留言内容:</strong></div></td>
<td><?php echo $row_rs['content']; ?></td>
</tr>
<?php if($row_rs['replied']==1)    { ?>
<tr>
<td><div align="right"><strong>回复:</strong></div></td>
<td><p><?php echo $row_rs['replycontent']; ?></p>
<p align="right"><strong>回复人:</strong><?php echo $row_rs['adminname']; ?></p></td>
</tr>
<?php } ?>
</table>
<br>
<?php } while ($row_rs = mysql_fetch_assoc($rs)); ?>
<p align="center">
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center">
<?php if ($pageNum_rs > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, 0, $queryString_rs); ?>">首页</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center">
<?php if ($pageNum_rs > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, max(0, $pageNum_rs - 1), $queryString_rs); ?>">上一页</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center">
<?php if ($pageNum_rs < $totalPages_rs) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, min($totalPages_rs, $pageNum_rs + 1), $queryString_rs); ?>">下一页</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center">
<?php if ($pageNum_rs < $totalPages_rs) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, $totalPages_rs, $queryString_rs); ?>">尾页</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p>&nbsp; </p>
</body>
</html>
<?php
mysql_free_result($rs);
?>

$_SESSION['PHP_SELF']:获取当前正在执行脚本的文件名

报歉!评论已关闭.

不想听你唠叨×