Discuz教程网

php mysql 留言本应用实例

[复制链接]
authicon dly 发表于 2011-9-12 14:26:01 | 显示全部楼层 |阅读模式
实例说明制作一个php+mysql留言本
代码如下:

  1. <?php
  2. $hostname_conn = "localhost";
  3. $database_conn = "test";
  4. $username_conn = "root";
  5. $password_conn = "1981427";
  6. $conn = mysql_connect($hostname_conn, $username_conn, $password_conn);
  7. ?>
复制代码

代码如下:


  1. <?php
  2. //该函数用于将一般字符串转换成SQL语句所需要的格式
  3. function GetSQLValueString($theValue, $theType)
  4. {
  5. $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  6. switch ($theType) {
  7. case "text":
  8. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  9. break;
  10. case "int":
  11. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  12. break;
  13. }
  14. return $theValue;
  15. }
  16. ?>
复制代码

代码如下:


  1. <?php
  2. session_start();
  3. //如果Session不存在,则跳转到Admin.php
  4. if (!(isset($_SESSION['MM_Username']))) {
  5. header("Location: admin.php");
  6. exit;
  7. }
  8. ?>
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php'); ?>
  2. <?php
  3. // *** Validate request to login to this site.
  4. session_start();
  5. $loginFormAction = $_SERVER['PHP_SELF'];
  6. if (isset($accesscheck)) {
  7. $GLOBALS['PrevUrl'] = $accesscheck;
  8. session_register('PrevUrl');
  9. }
  10. if (isset($_POST['username'])) {
  11. $loginUsername=$_POST['username'];
  12. $password=$_POST['password'];
  13. $MM_fldUserAuthorization = "";
  14. $MM_redirectLoginSuccess = "adminmain.php";
  15. $MM_redirectLoginFailed = "admin.php";
  16. $MM_redirecttoReferrer = false;
  17. mysql_select_db($database_conn, $conn);
  18. $LoginRS__query=sprintf("SELECT adminname, password FROM admin WHERE adminname='%s' AND password='%s'",
  19. get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  20. $LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
  21. $loginFoundUser = mysql_num_rows($LoginRS);
  22. if ($loginFoundUser) {
  23. $loginStrGroup = "";
  24. //declare two session variables and assign them
  25. $GLOBALS['MM_Username'] = $loginUsername;
  26. $GLOBALS['MM_UserGroup'] = $loginStrGroup;
  27. //register the session variables
  28. session_register("MM_Username");
  29. session_register("MM_UserGroup");
  30. if (isset($_SESSION['PrevUrl']) && false) {
  31. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  32. }
  33. header("Location: " . $MM_redirectLoginSuccess );
  34. }
  35. else {
  36. header("Location: ". $MM_redirectLoginFailed );
  37. }
  38. }
  39. ?>
  40. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  41. <html>
  42. <head>
  43. <title>Untitled Document</title>
  44. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  45. <style type="text/css"><!--
  46. .style1 {font-size: 18px;
  47. font-weight: bold;
  48. }
  49. .style2 {font-size: 14px}
  50. --></style><style type="text/css" bogus="1">.style1 {font-size: 18px;
  51. font-weight: bold;
  52. }
  53. .style2 {font-size: 14px}</style>
  54. </head>
  55. <body>
  56. <p align="center"><span class="style1">留言板 - 管理登陆</span></p>
  57. <p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言</a> | <a href="newpost.php" href="newpost.php">发表留言</a></span></p>
  58. <form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  59. <table width="239" border="0" align="center">
  60. <tr>
  61. <td width="73">用户名:</td>
  62. <td width="156"><input name="username" type="text" id="username"></td>
  63. </tr>
  64. <tr>
  65. <td>密码:</td>
  66. <td><input name="password" type="password" id="password"></td>
  67. </tr>
  68. <tr>
  69. <td> </td>
  70. <td><input type="submit" name="Submit" value="提交">
  71. <input type="reset" name="Submit2" value="重设"></td>
  72. </tr>
  73. </table>
  74. </form>
  75. <p align="center"> </p>
  76. </body>
  77. </html>
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php');
  2. require_once('inc/accesscheck.php');
  3. require_once('inc/GetSQLValueString.php');?>
  4. <?php
  5. if ((isset($_GET['postid'])) && ($_GET['postid'] != "")) {
  6. $updateSQL = sprintf("UPDATE posts SET checked=1-checked WHERE postid=%s",
  7. GetSQLValueString($_GET['postid'], "int"));
  8. mysql_select_db($database_conn, $conn);
  9. $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());
  10. $deleteGoTo = "adminmain.php";
  11. if (isset($_SERVER['QUERY_STRING'])) {
  12. $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
  13. $deleteGoTo .= $_SERVER['QUERY_STRING'];
  14. }
  15. header(sprintf("Location: %s", $deleteGoTo));
  16. }
  17. ?>
复制代码

代码如下:


  1. <?php
  2. require_once('Connections/conn.php');
  3. require_once('inc/accesscheck.php');
  4. require_once('inc/GetSQLValueString.php');
  5. ?>
  6. <?php
  7. if ((isset($_GET['postid'])) && ($_GET['postid'] != "")) {
  8. $deleteSQL = sprintf("DELETE FROM posts WHERE postid=%s",
  9. GetSQLValueString($_GET['postid'], "int"));
  10. mysql_select_db($database_conn, $conn);
  11. $Result1 = mysql_query($deleteSQL, $conn) or die(mysql_error());
  12. $deleteGoTo = "adminmain.php";
  13. if (isset($_SERVER['QUERY_STRING'])) {
  14. $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
  15. $deleteGoTo .= $_SERVER['QUERY_STRING'];
  16. }
  17. header(sprintf("Location: %s", $deleteGoTo));
  18. }
  19. ?>
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php');
  2. require_once('inc/accesscheck.php');
  3. require_once('inc/GetSQLValueString.php');?>
  4. <?php
  5. if ((isset($_GET['postid'])) && ($_GET['postid'] != "")) {
  6. $deleteSQL = sprintf("UPDATE posts SET replied=0, adminname='', replycontent='' WHERE postid=%s",
  7. GetSQLValueString($_GET['postid'], "int"));
  8. mysql_select_db($database_conn, $conn);
  9. $Result1 = mysql_query($deleteSQL, $conn) or die(mysql_error());
  10. $deleteGoTo = "adminmain.php";
  11. if (isset($_SERVER['QUERY_STRING'])) {
  12. $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
  13. $deleteGoTo .= $_SERVER['QUERY_STRING'];
  14. }
  15. header(sprintf("Location: %s", $deleteGoTo));
  16. }
  17. ?>
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php');
  2. require_once('inc/accesscheck.php');
  3. require_once('inc/GetSQLValueString.php');?>
  4. <?php
  5. mysql_select_db($database_conn, $conn);
  6. $query_rs = "SELECT * FROM posts ORDER BY postid DESC";
  7. $rs = mysql_query($query_rs, $conn) or die(mysql_error());
  8. $row_rs = mysql_fetch_assoc($rs);
  9. $totalRows_rs = mysql_num_rows($rs);
  10. ?>
  11. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  12. <html>
  13. <head>
  14. <title>Untitled Document</title>
  15. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  16. <style type="text/css"><!--
  17. .style1 {font-size: 18px;
  18. font-weight: bold;
  19. }
  20. .style2 {font-size: 14px}
  21. .style4 {font-size: 12px}
  22. .style6 {font-size: 12px; font-weight: bold; }
  23. --></style><style type="text/css" bogus="1">.style1 {font-size: 18px;
  24. font-weight: bold;
  25. }
  26. .style2 {font-size: 14px}
  27. .style4 {font-size: 12px}
  28. .style6 {font-size: 12px; font-weight: bold; }</style>
  29. </head>
  30. <body>
  31. <p align="center"><span class="style1">留言板 - 管理页面</span></p>
  32. <p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言</a> | <a href="newpost.php" href="newpost.php">发表留言</a> | <a href="logout.php" href="logout.php">退出登陆</a></span></p>
  33. <p align="center"> </p>
  34. <table width="623" border="1" align="center" cellpadding="0" cellspacing="0">
  35. <tr>
  36. <td width="91"><span class="style6">留言者用户名</span></td>
  37. <td width="210"><span class="style6">留言标题</span></td>
  38. <td width="61"> </td>
  39. <td width="61"> </td>
  40. <td width="61"> </td>
  41. <td width="62"> </td>
  42. </tr>
  43. <?php do { ?>
  44. <tr>
  45. <td><span class="style4"><?php echo $row_rs['username']; ?></span></td>
  46. <td><span class="style4"><?php
  47. echo $row_rs['topic'];
  48. if($row_rs['checked']==1)
  49. echo "(已审批)";
  50. if($row_rs['replied']==1)
  51. echo "(已回复)";
  52. ?></span></td>
  53. <td><div align="center"><span class="style4"><a href="adminreply.php?postid=<?php echo $row_rs['postid']; ?>">回复留言</a></span></div></td>
  54. <td><div align="center"><span class="style4"><a href="admindelpost.php?postid=<?php echo $row_rs['postid']; ?>">删除留言</a></span></div></td>
  55. <td><div align="center"><span class="style4"><a href="admindelreply.php?postid=<?php echo $row_rs['postid']; ?>">删除回复</a></span></div></td>
  56. <td><div align="center"><span class="style4"><a href="admincheckpost.php?postid=<?php echo $row_rs['postid']; ?>">审批留言</a></span></div></td>
  57. </tr>
  58. <?php } while ($row_rs = mysql_fetch_assoc($rs)); ?>
  59. </table>
  60. <p align="center"> </p>
  61. </body>
  62. </html>
  63. <?php
  64. mysql_free_result($rs);
  65. ?>
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php');
  2. require_once('inc/accesscheck.php');
  3. require_once('inc/GetSQLValueString.php');?>
  4. <?php
  5. $editFormAction = $_SERVER['PHP_SELF'];
  6. if (isset($_SERVER['QUERY_STRING'])) {
  7. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  8. }
  9. if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  10. $updateSQL = sprintf("UPDATE posts SET replycontent=%s, replied=1, checked=1, adminname=%s WHERE postid=%s",
  11. GetSQLValueString($_POST['replycontent'], "text"),
  12. GetSQLValueString($_SESSION['MM_Username'], "text"),
  13. GetSQLValueString($_POST['postid'], "int"));
  14. mysql_select_db($database_conn, $conn);
  15. $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());
  16. echo "<script type="text/javascript"><!--
  17. alert('回复发表成功');
  18. // --></script>";
  19. }
  20. $colname_rs = "1";
  21. if (isset($_GET['postid'])) {
  22. $colname_rs = (get_magic_quotes_gpc()) ? $_GET['postid'] : addslashes($_GET['postid']);
  23. }
  24. mysql_select_db($database_conn, $conn);
  25. $query_rs = sprintf("SELECT * FROM posts WHERE postid = %s", $colname_rs);
  26. $rs = mysql_query($query_rs, $conn) or die(mysql_error());
  27. $row_rs = mysql_fetch_assoc($rs);
  28. $totalRows_rs = mysql_num_rows($rs);
  29. ?>
  30. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  31. <html>
  32. <head>
  33. <title>Untitled Document</title>
  34. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  35. <style type="text/css"><!--
  36. .style1 {font-size: 18px;
  37. font-weight: bold;
  38. }
  39. .style2 {font-size: 14px}
  40. --></style><style type="text/css" bogus="1">.style1 {font-size: 18px;
  41. font-weight: bold;
  42. }
  43. .style2 {font-size: 14px}</style>
  44. </head>
  45. <body>
  46. <p align="center"><span class="style1">留言板 - 管理页面 - 回复留言</span></p>
  47. <p align="center"><span class="style2"><a href="adminmain.php" href="adminmain.php">管理页面</a><a href="newpost.php" href="newpost.php"></a> | <a href="logout.php" href="logout.php">退出登陆</a></span></p>
  48. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  49. <table align="center">
  50. <tr valign="baseline">
  51. <td nowrap align="right" valign="top">留言标题:</td>
  52. <td><?php echo $row_rs['topic']; ?></td>
  53. </tr>
  54. <tr valign="baseline">
  55. <td nowrap align="right" valign="top">留言内容:</td>
  56. <td><?php echo $row_rs['content']; ?></td>
  57. </tr>
  58. <tr valign="baseline">
  59. <td nowrap align="right" valign="top">回复内容:</td>
  60. <td>
  61. <textarea name="replycontent" cols="50" rows="5"><?php echo $row_rs['replycontent']; ?>
复制代码

代码如下:

  1. <?php
  2. $logoutGoTo = "admin.php";
  3. session_start();
  4. unset($_SESSION['MM_Username']);
  5. unset($_SESSION['MM_UserGroup']);
  6. if ($logoutGoTo != "") {header("Location: $logoutGoTo");
  7. session_unregister('MM_Username');
  8. session_unregister('MM_UserGroup');
  9. exit;
  10. }
  11. ?>
  12. <?php
  13. $logoutGoTo = "admin.php";
  14. session_start();
  15. unset($_SESSION['MM_Username']);
  16. unset($_SESSION['MM_UserGroup']);
  17. if ($logoutGoTo != "") {header("Location: $logoutGoTo");
  18. session_unregister('MM_Username');
  19. session_unregister('MM_UserGroup');
  20. exit;
  21. }
  22. ?>
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php');
  2. require_once('inc/GetSQLValueString.php');?>
  3. <?php
  4. $editFormAction = $_SERVER['PHP_SELF'];
  5. if (isset($_SERVER['QUERY_STRING'])) {
  6. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  7. }
  8. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  9. $insertSQL = sprintf("INSERT INTO posts (username, topic, content) VALUES (%s, %s, %s)",
  10. GetSQLValueString($_POST['username'], "text"),
  11. GetSQLValueString($_POST['topic'], "text"),
  12. GetSQLValueString($_POST['content'], "text"));
  13. mysql_select_db($database_conn, $conn);
  14. $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
  15. echo "<script type="text/javascript"><!--
  16. alert('留言发表成功');
  17. // --></script>";
  18. }
  19. ?>
  20. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  21. <html>
  22. <head>
  23. <title>Untitled Document</title>
  24. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  25. <style type="text/css"><!--
  26. .style1 { font-size: 18px;
  27. font-weight: bold;
  28. }
  29. .style2 {font-size: 14px}
  30. --></style><style type="text/css" bogus="1">.style1 { font-size: 18px;
  31. font-weight: bold;
  32. }
  33. .style2 {font-size: 14px}</style>
  34. </head>
  35. <body>
  36. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  37. <p align="center"><span class="style1">留言板 - 发表新留言</span></p>
  38. <p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言</a> | <a href="admin.php" href="admin.php">管理登陆</a></span></p>
  39. <table align="center">
  40. <tr valign="baseline">
  41. <td nowrap align="right">用户名:</td>
  42. <td><input type="text" name="username" value="" size="32"></td>
  43. </tr>
  44. <tr valign="baseline">
  45. <td nowrap align="right">标题:</td>
  46. <td><input type="text" name="topic" value="" size="32"></td>
  47. </tr>
  48. <tr valign="baseline">
  49. <td nowrap align="right" valign="top">留言内容:</td>
  50. <td>
  51. <textarea name="content" cols="50" rows="5">
  52. <?php require_once('Connections/conn.php');
  53. require_once('inc/GetSQLValueString.php');?>
  54. <?php
  55. $editFormAction = $_SERVER['PHP_SELF'];
  56. if (isset($_SERVER['QUERY_STRING'])) {
  57. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  58. }
  59. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  60. $insertSQL = sprintf("INSERT INTO posts (username, topic, content) VALUES (%s, %s, %s)",
  61. GetSQLValueString($_POST['username'], "text"),
  62. GetSQLValueString($_POST['topic'], "text"),
  63. GetSQLValueString($_POST['content'], "text"));
  64. mysql_select_db($database_conn, $conn);
  65. $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
  66. echo "<script type="text/javascript"><!--
  67. alert('留言发表成功');
  68. // --></script>";
  69. }
  70. ?>
复制代码

代码如下:


  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  6. <style type="text/css"><!--
  7. .style1 { font-size: 18px;
  8. font-weight: bold;
  9. }
  10. .style2 {font-size: 14px}
  11. --></style><style type="text/css" bogus="1">.style1 { font-size: 18px;
  12. font-weight: bold;
  13. }
  14. .style2 {font-size: 14px}</style>
  15. </head>
  16. <body>
  17. <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  18. <p align="center"><span class="style1">留言板 - 发表新留言</span></p>
  19. <p align="center"><span class="style2"><a href="viewposts.php" href="viewposts.php">浏览留言</a> | <a href="admin.php" href="admin.php">管理登陆</a></span></p>
  20. <table align="center">
  21. <tr valign="baseline">
  22. <td nowrap align="right">用户名:</td>
  23. <td><input type="text" name="username" value="" size="32"></td>
  24. </tr>
  25. <tr valign="baseline">
  26. <td nowrap align="right">标题:</td>
  27. <td><input type="text" name="topic" value="" size="32"></td>
  28. </tr>
  29. <tr valign="baseline">
  30. <td nowrap align="right" valign="top">留言内容:</td>
  31. <td>
  32. <textarea name="content" cols="50" rows="5">
复制代码

代码如下:


  1. <?php require_once('Connections/conn.php'); ?>
  2. <?php
  3. $currentPage = $_SERVER["PHP_SELF"];
  4. $maxRows_rs = 10;
  5. $pageNum_rs = 0;
  6. if (isset($_GET['pageNum_rs'])) {
  7. $pageNum_rs = $_GET['pageNum_rs'];
  8. }
  9. $startRow_rs = $pageNum_rs * $maxRows_rs;
  10. mysql_select_db($database_conn, $conn);
  11. $query_rs = "SELECT * FROM posts WHERE checked=1 ORDER BY postid DESC";
  12. $query_limit_rs = sprintf("%s LIMIT %d, %d", $query_rs, $startRow_rs, $maxRows_rs);
  13. $rs = mysql_query($query_limit_rs, $conn) or die(mysql_error());
  14. $row_rs = mysql_fetch_assoc($rs);
  15. if (isset($_GET['totalRows_rs'])) {
  16. $totalRows_rs = $_GET['totalRows_rs'];
  17. } else {
  18. $all_rs = mysql_query($query_rs);
  19. $totalRows_rs = mysql_num_rows($all_rs);
  20. }
  21. $totalPages_rs = ceil($totalRows_rs/$maxRows_rs)-1;
  22. $queryString_rs = "";
  23. if (!emptyempty($_SERVER['QUERY_STRING'])) {
  24. $params = explode("&", $_SERVER['QUERY_STRING']);
  25. $newParams = array();
  26. foreach ($params as $param) {
  27. if (stristr($param, "pageNum_rs") == false &&
  28. stristr($param, "totalRows_rs") == false) {
  29. array_push($newParams, $param);
  30. }
  31. }
  32. if (count($newParams) != 0) {
  33. $queryString_rs = "&" . htmlentities(implode("&", $newParams));
  34. }
  35. }
  36. $queryString_rs = sprintf("&totalRows_rs=%d%s", $totalRows_rs, $queryString_rs);
  37. ?>
  38. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  39. <html>
  40. <head>
  41. <title>Untitled Document</title>
  42. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  43. <style type="text/css"><!--
  44. .style1 {
  45. font-size: 18px;
  46. font-weight: bold;
  47. }
  48. .style2 {font-size: 14px}
  49. --></style><style type="text/css" bogus="1">.style1 {
  50. font-size: 18px;
  51. font-weight: bold;
  52. }
  53. .style2 {font-size: 14px}</style>
  54. </head>
  55. <body>
  56. <p align="center" class="style1">留言板 - 留言浏览</p>
  57. <p align="center" class="style2"><a href="newpost.php" href="newpost.php">发表留言</a> | <a href="admin.php" href="admin.php">管理登陆</a></p>
  58. <?php do { ?>
  59. <table width="500" border="1" align="center" cellpadding="0" cellspacing="0">
  60. <tr>
  61. <td width="116"><div align="right"><strong>用户名:</strong></div></td>
  62. <td width="378"><?php echo $row_rs['username']; ?></td>
  63. </tr>
  64. <tr>
  65. <td><div align="right"><strong>标题:</strong></div></td>
  66. <td><?php echo $row_rs['topic']; ?></td>
  67. </tr>
  68. <tr>
  69. <td><div align="right"><strong>留言内容:</strong></div></td>
  70. <td><?php echo $row_rs['content']; ?></td>
  71. </tr>
  72. <?php if($row_rs['replied']==1) { ?>
  73. <tr>
  74. <td><div align="right"><strong>回复:</strong></div></td>
  75. <td><p><?php echo $row_rs['replycontent']; ?></p>
  76. <p align="right"><strong>回复人:</strong><?php echo $row_rs['adminname']; ?></p></td>
  77. </tr>
  78. <?php } ?>
  79. </table>
  80. <br>
  81. <?php } while ($row_rs = mysql_fetch_assoc($rs)); ?>
  82. <p align="center">
  83. <table border="0" width="50%" align="center">
  84. <tr>
  85. <td width="23%" align="center">
  86. <?php if ($pageNum_rs > 0) { // Show if not first page ?>
  87. <a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, 0, $queryString_rs); ?>">首页</a>
  88. <?php } // Show if not first page ?>
  89. </td>
  90. <td width="31%" align="center">
  91. <?php if ($pageNum_rs > 0) { // Show if not first page ?>
  92. <a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, max(0, $pageNum_rs - 1), $queryString_rs); ?>">上一页</a>
  93. <?php } // Show if not first page ?>
  94. </td>
  95. <td width="23%" align="center">
  96. <?php if ($pageNum_rs < $totalPages_rs) { // Show if not last page ?>
  97. <a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, min($totalPages_rs, $pageNum_rs + 1), $queryString_rs); ?>">下一页</a>
  98. <?php } // Show if not last page ?>
  99. </td>
  100. <td width="23%" align="center">
  101. <?php if ($pageNum_rs < $totalPages_rs) { // Show if not last page ?>
  102. <a href="<?php printf(" href="<?php printf("%s?pageNum_rs=%d%s", $currentPage, $totalPages_rs, $queryString_rs); ?>">尾页</a>
  103. <?php } // Show if not last page ?>
  104. </td>
  105. </tr>
  106. </table>
  107. </p>
  108. <p> </p>
  109. </body>
  110. </html>
  111. <?php
  112. mysql_free_result($rs);
  113. ?>
复制代码




上一篇:PHP数组的一些常见操作汇总
下一篇:PHP下几个常用的去空、分组、调试数组函数
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 05:01

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表