简易 文章发布系统——前台界面

源自 慕课网 的学习
       关于简易文章发布系统——后台管理系统大致已经制作完毕,但是从安全方面来看,程序质量不高,只适合初学者进行学习开发,掌握php的开发流程和开发技巧,为以后引擎模板的学习打下基础。
       针对 后台管理系统,制作 简易文章发布系统的前台界面,用于用户的查看。
       使用同样的数据库和数据表,基于原来的目录结构进行设计:

       先来看下,前台文章展示的效果页:
       文章列表页 article.list.php

      样式 default.css
  1. /* 
  2. Design by Free CSS Templates 
  3. http://www.freecsstemplates.org 
  4. Released for free under a Creative Commons Attribution 2.5 License 
  5. */  
  6.   
  7. body {  
  8.     margin0;  
  9.     padding0;  
  10.     background#FFFFFF;  
  11.     font-familyArialHelveticasans-serif;  
  12.     font-size13px;  
  13.     color#6D6D6D;  
  14. }  
  15.   
  16. h1, h2, h3 {  
  17.     margin0;  
  18.     text-transformlowercase;  
  19.     font-weightnormal;  
  20.     color#78CC00;  
  21. }  
  22.   
  23. h1 {  
  24.     letter-spacing-1px;  
  25.     font-size32px;  
  26. }  
  27.   
  28. h2 {  
  29.     font-size23px;  
  30. }  
  31.   
  32. p, ul, ol {  
  33.     margin0 0 2em 0;  
  34.     text-alignjustify;  
  35.     line-height26px;  
  36. }  
  37.   
  38. a:link {  
  39.     color#7AD000;  
  40. }  
  41.   
  42. a:hover, a:active {  
  43.     text-decorationnone;  
  44.     color#7AD000;  
  45. }  
  46.   
  47. a:visited {  
  48.     color#7AD000;  
  49. }  
  50.   
  51. img {  
  52.     bordernone;  
  53. }  
  54.   
  55. img.left {  
  56.     floatleft;  
  57.     margin7px 15px 0 0;  
  58. }  
  59.   
  60. img.right {  
  61.     floatright;  
  62.     margin7px 0 0 15px;  
  63. }  
  64.   
  65. /* Form */  
  66.   
  67. form {  
  68.     margin0;  
  69.     padding0;  
  70. }  
  71.   
  72. fieldset {  
  73.     margin0;  
  74.     padding0;  
  75.     bordernone;  
  76. }  
  77.   
  78. legend {  
  79.     displaynone;  
  80. }  
  81.   
  82. input, textarea, select {  
  83.     font-family"Trebuchet MS"ArialHelveticasans-serif;  
  84.     font-size13px;  
  85.     color#333333;  
  86. }  
  87.   
  88. #wrapper {  
  89.     background#7ACF00 url(images/img03.jpg);  
  90. }  
  91.   
  92. /* Header */  
  93.   
  94. #header {  
  95.     width900px;  
  96.     height80px;  
  97.     margin0 auto 20px auto;  
  98.     padding-top10px;  
  99. }  
  100.   
  101. #logo {  
  102.     floatleft;  
  103.     height120px;  
  104.     margin-left30px;  
  105. }  
  106.   
  107. #logo h1 {  
  108.     font-size38px;  
  109.     color#3399CC;  
  110. }  
  111.   
  112. #logo h1 sup {  
  113.     vertical-aligntext-top;  
  114.     font-size24px;  
  115. }  
  116.   
  117. #logo h1 a {  
  118.     color#FFFFFF;  
  119. }  
  120.   
  121. #logo h2 {  
  122.     text-transformuppercase;  
  123.     font-familyArialHelveticasans-serif;  
  124.     font-size10px;  
  125.     color#FFFFFF;  
  126. }  
  127.   
  128. #logo a {  
  129.     text-decorationnone;  
  130.     color#FFFFFF;  
  131. }  
  132.   
  133. /* Menu */  
  134.   
  135. #menu {  
  136.     floatright;  
  137. }  
  138.   
  139. #menu ul {  
  140.     margin0;  
  141.     padding28px 0 0 0;  
  142.     list-stylenone;  
  143. }  
  144.   
  145. #menu li {  
  146.     displayinline;  
  147. }  
  148.   
  149. #menu a {  
  150.     displayblock;  
  151.     floatleft;  
  152.     margin-left5px;  
  153.     background#6AB000;  
  154.     padding7px 10px;  
  155.     text-decorationnone;  
  156.     font-size15px;  
  157.     color#FFFFFF;  
  158. }  
  159.   
  160. #menu a:hover {  
  161.     text-decorationunderline;  
  162. }  
  163.   
  164. #menu .active a {  
  165. }  
  166.   
  167. /* Page */  
  168.   
  169. #page {  
  170.     width900px;  
  171.     margin0 auto;  
  172.     padding20px 20px;  
  173. }  
  174.   
  175. /* Content */  
  176.   
  177. #content {  
  178.     floatleft;  
  179.     width590px;  
  180.     padding0px 30px 0px 30px;  
  181. }  
  182.   
  183. /* Post */  
  184.   
  185. .post {  
  186. }  
  187.   
  188. .post .title {  
  189.     margin-bottom20px;  
  190.     padding-bottom5px;  
  191.     border-bottom10px solid #EDEDED;  
  192. }  
  193.   
  194. .post .entry {  
  195. }  
  196.   
  197. .post .meta {  
  198.     margin0;  
  199.     padding0 0 60px 0;  
  200.     backgroundurl(images/img04.jpg) repeat-x left 30%;  
  201. }  
  202.   
  203. .post .meta p {  
  204.     margin0;  
  205.     line-heightnormal;  
  206. }  
  207.   
  208. .post .meta .byline {  
  209.     floatleft;  
  210.     color#0000FF;  
  211. }  
  212.   
  213. .post .meta .links {  
  214.     floatleft;  
  215. }  
  216.   
  217. .post .meta .more {  
  218.     width185px;  
  219.     height35px;  
  220.     padding5px 0px 5px 0px;  
  221.     text-transformuppercase;  
  222.     text-decorationnone;  
  223.     font-size11px;  
  224. }  
  225.   
  226. .post .meta .comments {  
  227.     padding5px 0px 5px 0px;  
  228.     text-transformuppercase;  
  229.     text-decorationnone;  
  230.     font-size11px;  
  231. }  
  232.   
  233. .post .meta b {  
  234.     displaynone;  
  235. }  
  236.   
  237. /* Sidebar */  
  238.   
  239. #sidebar {  
  240.     floatright;  
  241.     width230px;  
  242. }  
  243.   
  244. #sidebar ul {  
  245.     margin0;  
  246.     padding10px 0 0 0;  
  247.     list-stylenone;  
  248. }  
  249.   
  250. #sidebar li {  
  251.     margin-bottom40px;  
  252. }  
  253.   
  254. #sidebar li ul {  
  255. }  
  256.   
  257. #sidebar li li {  
  258.     margin0;  
  259.     padding3px 0;  
  260.     border-bottom1px dashed #D1D1D1;  
  261. }  
  262.   
  263. #sidebar li li a {  
  264.     margin0;  
  265.     padding-left25px;  
  266.     backgroundurl(images/img01.png) no-repeat left 50%;  
  267. }  
  268.   
  269. #sidebar h2 {  
  270.     margin-bottom10px;  
  271.     padding-bottom5px;  
  272.     border-bottom10px solid #EDEDED;  
  273.     font-size18px;  
  274.     font-weightnormal;  
  275. }  
  276.   
  277. #sidebar a {  
  278.     text-decorationnone;  
  279.     color#6D6D6D;  
  280. }  
  281.   
  282. /* Search */  
  283.   
  284. #search {  
  285. }  
  286.   
  287. #search h2 {  
  288.     margin-bottom20px;  
  289. }  
  290.   
  291. #s {  
  292.     width150px;  
  293.     margin-right5px;  
  294.     padding3px;  
  295.     border1px solid #F0F0F0;  
  296. }  
  297.   
  298. #x {  
  299.     padding3px;  
  300.     background#ECECEC url(images/img08.gif) repeat-x left bottom;  
  301.     bordernone;  
  302.     text-transformlowercase;  
  303.     font-size11px;  
  304.     color#4F4F4F;  
  305. }  
  306.   
  307. /* Boxes */  
  308.   
  309. .box1 {  
  310.     padding20px;  
  311.     backgroundurl(images/img05.gif) no-repeat;  
  312. }  
  313.   
  314. .box2 {  
  315.     color#BABABA;  
  316. }  
  317.   
  318. .box2 h2 {  
  319.     margin-bottom15px;  
  320.     backgroundurl(images/img10.gif) repeat-x left bottom;  
  321.     font-size16px;  
  322.     color#FFFFFF;  
  323. }  
  324.   
  325. .box2 ul {  
  326.     margin0;  
  327.     padding0;  
  328.     list-stylenone;  
  329. }  
  330.   
  331. .box2 a:link, .box2 a:hover, .box2 a:active, .box2 a:visited  {  
  332.     color#EDEDED;  
  333. }  
  334.   
  335. /* Footer */  
  336.   
  337. #footer {  
  338.     height400px;  
  339.     min-height74px;  
  340.     padding10px 0 0 0;  
  341.     background#979797 url(images/img02.jpg) repeat-x left top;  
  342.     font-familyTahomaArialHelveticasans-serif;  
  343. }  
  344.   
  345. html>body #footer {  
  346.     heightauto;  
  347. }  
  348.   
  349. #legal {  
  350.     clearboth;  
  351.     padding-top20px;  
  352.     text-aligncenter;  
  353.     text-transformuppercase;  
  354.     font-size10px;  
  355.     color#353535;  
  356. }  
  357.   
  358. #legal a {  
  359.     font-weightbold;  
  360.     color#FFFFFF;  
  361. }  
/*
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
*/

body {
	margin: 0;
	padding: 0;
	background: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 13px;
	color: #6D6D6D;
}

h1, h2, h3 {
	margin: 0;
	text-transform: lowercase;
	font-weight: normal;
	color: #78CC00;
}

h1 {
	letter-spacing: -1px;
	font-size: 32px;
}

h2 {
	font-size: 23px;
}

p, ul, ol {
	margin: 0 0 2em 0;
	text-align: justify;
	line-height: 26px;
}

a:link {
	color: #7AD000;
}

a:hover, a:active {
	text-decoration: none;
	color: #7AD000;
}

a:visited {
	color: #7AD000;
}

img {
	border: none;
}

img.left {
	float: left;
	margin: 7px 15px 0 0;
}

img.right {
	float: right;
	margin: 7px 0 0 15px;
}

/* Form */

form {
	margin: 0;
	padding: 0;
}

fieldset {
	margin: 0;
	padding: 0;
	border: none;
}

legend {
	display: none;
}

input, textarea, select {
	font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
	font-size: 13px;
	color: #333333;
}

#wrapper {
	background: #7ACF00 url(images/img03.jpg);
}

/* Header */

#header {
	width: 900px;
	height: 80px;
	margin: 0 auto 20px auto;
	padding-top: 10px;
}

#logo {
	float: left;
	height: 120px;
	margin-left: 30px;
}

#logo h1 {
	font-size: 38px;
	color: #3399CC;
}

#logo h1 sup {
	vertical-align: text-top;
	font-size: 24px;
}

#logo h1 a {
	color: #FFFFFF;
}

#logo h2 {
	text-transform: uppercase;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FFFFFF;
}

#logo a {
	text-decoration: none;
	color: #FFFFFF;
}

/* Menu */

#menu {
	float: right;
}

#menu ul {
	margin: 0;
	padding: 28px 0 0 0;
	list-style: none;
}

#menu li {
	display: inline;
}

#menu a {
	display: block;
	float: left;
	margin-left: 5px;
	background: #6AB000;
	padding: 7px 10px;
	text-decoration: none;
	font-size: 15px;
	color: #FFFFFF;
}

#menu a:hover {
	text-decoration: underline;
}

#menu .active a {
}

/* Page */

#page {
	width: 900px;
	margin: 0 auto;
	padding: 20px 20px;
}

/* Content */

#content {
	float: left;
	width: 590px;
	padding: 0px 30px 0px 30px;
}

/* Post */

.post {
}

.post .title {
	margin-bottom: 20px;
	padding-bottom: 5px;
	border-bottom: 10px solid #EDEDED;
}

.post .entry {
}

.post .meta {
	margin: 0;
	padding: 0 0 60px 0;
	background: url(images/img04.jpg) repeat-x left 30%;
}

.post .meta p {
	margin: 0;
	line-height: normal;
}

.post .meta .byline {
	float: left;
	color: #0000FF;
}

.post .meta .links {
	float: left;
}

.post .meta .more {
	width: 185px;
	height: 35px;
	padding: 5px 0px 5px 0px;
	text-transform: uppercase;
	text-decoration: none;
	font-size: 11px;
}

.post .meta .comments {
	padding: 5px 0px 5px 0px;
	text-transform: uppercase;
	text-decoration: none;
	font-size: 11px;
}

.post .meta b {
	display: none;
}

/* Sidebar */

#sidebar {
	float: right;
	width: 230px;
}

#sidebar ul {
	margin: 0;
	padding: 10px 0 0 0;
	list-style: none;
}

#sidebar li {
	margin-bottom: 40px;
}

#sidebar li ul {
}

#sidebar li li {
	margin: 0;
	padding: 3px 0;
	border-bottom: 1px dashed #D1D1D1;
}

#sidebar li li a {
	margin: 0;
	padding-left: 25px;
	background: url(images/img01.png) no-repeat left 50%;
}

#sidebar h2 {
	margin-bottom: 10px;
	padding-bottom: 5px;
	border-bottom: 10px solid #EDEDED;
	font-size: 18px;
	font-weight: normal;
}

#sidebar a {
	text-decoration: none;
	color: #6D6D6D;
}

/* Search */

#search {
}

#search h2 {
	margin-bottom: 20px;
}

#s {
	width: 150px;
	margin-right: 5px;
	padding: 3px;
	border: 1px solid #F0F0F0;
}

#x {
	padding: 3px;
	background: #ECECEC url(images/img08.gif) repeat-x left bottom;
	border: none;
	text-transform: lowercase;
	font-size: 11px;
	color: #4F4F4F;
}

/* Boxes */

.box1 {
	padding: 20px;
	background: url(images/img05.gif) no-repeat;
}

.box2 {
	color: #BABABA;
}

.box2 h2 {
	margin-bottom: 15px;
	background: url(images/img10.gif) repeat-x left bottom;
	font-size: 16px;
	color: #FFFFFF;
}

.box2 ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.box2 a:link, .box2 a:hover, .box2 a:active, .box2 a:visited  {
	color: #EDEDED;
}

/* Footer */

#footer {
	height: 400px;
	min-height: 74px;
	padding: 10px 0 0 0;
	background: #979797 url(images/img02.jpg) repeat-x left top;
	font-family: Tahoma, Arial, Helvetica, sans-serif;
}

html>body #footer {
	height: auto;
}

#legal {
	clear: both;
	padding-top: 20px;
	text-align: center;
	text-transform: uppercase;
	font-size: 10px;
	color: #353535;
}

#legal a {
	font-weight: bold;
	color: #FFFFFF;
}

       通过对数据库info进行所有的文章显示即可, article.list.php如下:
  1. <?php  
  2.     require_once('connect.php');  
  3.     $sql = "select * from article order by dateline desc";  
  4.     $query = mysql_query($sql);  
  5.     if($query && mysql_num_rows($query)) {  
  6.         while($row = mysql_fetch_assoc($query)) {  
  7.             $data[] = $row;  
  8.         }  
  9.     } else {  
  10.         $data = [];  
  11.     }  
  12. ?>  
  13. <!DOCTYPE html>  
  14. <html lang="en">  
  15. <head>  
  16.     <meta charset="UTF-8">  
  17.     <title>文章发布系统</title>  
  18.     <meta name="keywords" content=""/>  
  19.     <meta name="description" content="文章发布系统"/>  
  20.     <link rel="stylesheet" href="default.css" type="text/css">  
  21. </head>  
  22. <body>  
  23.     <div id="wrapper">  
  24.         <div id="header">  
  25.             <div id="logo">  
  26.                 <h1><a href="#">php与mysql<sup></sup></a></h1>  
  27.                 <h2></h2>  
  28.             </div>  
  29.   
  30.             <div id="menu">  
  31.                 <ul>  
  32.                     <li class="active"><a href="article.list.php">文章</a></li>  
  33.                     <li><a href="about.php">关于我们</a></li>  
  34.                     <li><a href="contact.php">联系我们</a></li>  
  35.                 </ul>  
  36.             </div>  
  37.         </div>  
  38.     </div>  
  39.   
  40.     <div id="page">  
  41.         <div id="content">  
  42.             <?php  
  43.                 if(empty($data)) {  
  44.                     echo "当前没有文章,请管理员在后台添加文章";  
  45.                 } else {  
  46.                     foreach ($data as $value) {  
  47.             ?>  
  48.                   
  49.                 <div class="post">  
  50.                     <h1 class="title"><?php echo $value['title']; ?><span style="color:#CCC; font-size:14px;">  作者:<?php echo $value['author'];?></span></h1>  
  51.                     <div class="entry">  
  52.                         <?php echo $value['description']; ?>  
  53.                     </div>  
  54.                     <div class="meta">  
  55.                         <p class="links"><a href="article.show.php?id=<?php echo $value['id']; ?>" class="more">查看详细</a>  »  </p>  
  56.                     </div>  
  57.                 </div>  
  58.   
  59.             <?php  
  60.                     }  
  61.                 }  
  62.             ?>  
  63.         </div>  
  64.   
  65.         <div id="sidebar">  
  66.             <ul>  
  67.                 <li id="search">  
  68.                     <h2><b class="text1">Search</b></h2>  
  69.                     <form action="article.search.php" method="get">  
  70.                         <fieldset>  
  71.                             <input type="text" id="s" name="key" value="">  
  72.                             <input type="submit" id="x" value="Search">  
  73.                         </fieldset>  
  74.                     </form>  
  75.                 </li>  
  76.             </ul>  
  77.         </div>  
  78.   
  79.         <div style="clear: both;"> </div>  
  80.     </div>  
  81.   
  82.     <div id="footer">  
  83.         <p id="legal">Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved</p>  
  84.     </div>  
  85. </body>  
  86. </html>  
<?php
	require_once('connect.php');
	$sql = "select * from article order by dateline desc";
	$query = mysql_query($sql);
	if($query && mysql_num_rows($query)) {
		while($row = mysql_fetch_assoc($query)) {
			$data[] = $row;
		}
	} else {
		$data = [];
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>文章发布系统</title>
	<meta name="keywords" content=""/>
	<meta name="description" content="文章发布系统"/>
	<link rel="stylesheet" href="default.css" type="text/css">
</head>
<body>
	<div id="wrapper">
		<div id="header">
			<div id="logo">
				<h1><a href="#">php与mysql<sup></sup></a></h1>
				<h2></h2>
			</div>

			<div id="menu">
				<ul>
					<li class="active"><a href="article.list.php">文章</a></li>
					<li><a href="about.php">关于我们</a></li>
					<li><a href="contact.php">联系我们</a></li>
				</ul>
			</div>
		</div>
	</div>

	<div id="page">
		<div id="content">
			<?php
				if(empty($data)) {
					echo "当前没有文章,请管理员在后台添加文章";
				} else {
					foreach ($data as $value) {
			?>
				
				<div class="post">
					<h1 class="title"><?php echo $value['title']; ?><span style="color:#CCC; font-size:14px;">  作者:<?php echo $value['author'];?></span></h1>
					<div class="entry">
						<?php echo $value['description']; ?>
					</div>
					<div class="meta">
						<p class="links"><a href="article.show.php?id=<?php echo $value['id']; ?>" class="more">查看详细</a>  »  </p>
					</div>
				</div>

			<?php
					}
				}
			?>
		</div>

		<div id="sidebar">
			<ul>
				<li id="search">
					<h2><b class="text1">Search</b></h2>
					<form action="article.search.php" method="get">
						<fieldset>
							<input type="text" id="s" name="key" value="">
							<input type="submit" id="x" value="Search">
						</fieldset>
					</form>
				</li>
			</ul>
		</div>

		<div style="clear: both;"> </div>
	</div>

	<div id="footer">
		<p id="legal">Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved</p>
	</div>
</body>
</html>
       点击“查看详细”即可查看该篇文章的详细内容,通过传递对应文章的id到 article.show.php, article.show.php 查询该文章所有信息进行展示。
       article.show.php
  1. <?php   
  2.     require_once('connect.php');  
  3.     $id = intval($_GET['id']); // intval 转化为 整数,有非法字符会转化为0,防止sql注入  
  4.     $sql = "select * from article where id = $id";  
  5.     $query = mysql_query($sql);  
  6.     if($query && mysql_num_rows($query)) {  
  7.         $row = mysql_fetch_assoc($query);  
  8.     } else {  
  9.         echo "这篇文章不存在";  
  10.         exit;  
  11.     }  
  12. ?>  
  13. <!DOCTYPE html>  
  14. <html lang="en">  
  15. <head>  
  16.     <meta charset="UTF-8">  
  17.     <title>文章详情页</title>  
  18.     <link rel="stylesheet" href="default.css" type="text/css">  
  19. </head>  
  20. <body>  
  21.     <div id="wrapper">  
  22.         <!-- start header -->  
  23.         <div id="header">  
  24.             <div id="logo">  
  25.                 <h1><a href="#">php与mysql<sup></sup></a></h1>  
  26.                 <h2></h2>  
  27.             </div>  
  28.             <div id="menu">  
  29.                 <ul>  
  30.                     <li class="active"><a href="article.list.php">文章</a></li>  
  31.                     <li><a href="#">关于我们</a></li>  
  32.                     <li><a href="#">联系我们</a></li>  
  33.                 </ul>  
  34.             </div>  
  35.         </div>  
  36.         <!-- end header -->  
  37.     </div>  
  38.   
  39.     <!-- start page -->  
  40.     <div id="page">  
  41.         <!-- start content -->  
  42.         <div id="content">  
  43.             <div class="post">  
  44.                 <h1 class="title"><!--文章标题放置到这里--><?php echo $row['title']?><span style="color:#ccc;font-size:14px;">  作者:<!--作者放置到这里--><?php echo $row['author'];?></span></h1>  
  45.                 <div class="entry">  
  46.                     <!--文章内容放置到这里-->  
  47.                     <?php echo $row['content']?>  
  48.                 </div>  
  49.             </div>  
  50.         </div>  
  51.         <!-- end content -->  
  52.         <!-- start sidebar -->  
  53.         <div id="sidebar">  
  54.             <ul>  
  55.                 <li id="search">  
  56.                     <h2><b class="text1">Search</b></h2>  
  57.                     <form method="get" action="article.search.php">  
  58.                         <fieldset>  
  59.                         <input type="text" id="s" name="key" value="" />  
  60.                         <input type="submit" id="x" value="Search" />  
  61.                         </fieldset>  
  62.                     </form>  
  63.                 </li>  
  64.             </ul>  
  65.         </div>  
  66.         <!-- end sidebar -->  
  67.         <div style="clear: both;"> </div>  
  68.     </div>  
  69.     <!-- end page -->  
  70.     <!-- start footer -->  
  71.     <div id="footer">  
  72.         <p id="legal"></p>  
  73.     </div>  
  74.     <!-- end footer -->  
  75. </body>  
  76. </html>  
<?php 
	require_once('connect.php');
	$id = intval($_GET['id']); // intval 转化为 整数,有非法字符会转化为0,防止sql注入
	$sql = "select * from article where id = $id";
	$query = mysql_query($sql);
	if($query && mysql_num_rows($query)) {
		$row = mysql_fetch_assoc($query);
	} else {
		echo "这篇文章不存在";
		exit;
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>文章详情页</title>
	<link rel="stylesheet" href="default.css" type="text/css">
</head>
<body>
	<div id="wrapper">
		<!-- start header -->
		<div id="header">
			<div id="logo">
				<h1><a href="#">php与mysql<sup></sup></a></h1>
				<h2></h2>
			</div>
			<div id="menu">
				<ul>
					<li class="active"><a href="article.list.php">文章</a></li>
					<li><a href="#">关于我们</a></li>
					<li><a href="#">联系我们</a></li>
				</ul>
			</div>
		</div>
		<!-- end header -->
	</div>

	<!-- start page -->
	<div id="page">
		<!-- start content -->
		<div id="content">
			<div class="post">
				<h1 class="title"><!--文章标题放置到这里--><?php echo $row['title']?><span style="color:#ccc;font-size:14px;">  作者:<!--作者放置到这里--><?php echo $row['author'];?></span></h1>
				<div class="entry">
					<!--文章内容放置到这里-->
					<?php echo $row['content']?>
				</div>
			</div>
		</div>
		<!-- end content -->
		<!-- start sidebar -->
		<div id="sidebar">
			<ul>
				<li id="search">
					<h2><b class="text1">Search</b></h2>
					<form method="get" action="article.search.php">
						<fieldset>
						<input type="text" id="s" name="key" value="" />
						<input type="submit" id="x" value="Search" />
						</fieldset>
					</form>
				</li>
			</ul>
		</div>
		<!-- end sidebar -->
		<div style="clear: both;"> </div>
	</div>
	<!-- end page -->
	<!-- start footer -->
	<div id="footer">
		<p id="legal"></p>
	</div>
	<!-- end footer -->
</body>
</html>

      如 点击查看一篇文章,结果如下:

       此外,在 article.list.php 即文章列表页,提供一个搜索功能,搜索含 关键字 的文章。点击“search”按钮,将要搜索的关键字发送给 article.search.php 进行搜索查找。
       article.search.php
  1. <?php  
  2.     require_once('connect.php');  
  3.     $key = $_GET['key'];  
  4.     $sql = "select * from article where title like '%$key%' order by dateline desc";  
  5.     $query = mysql_query($sql);  
  6.     if($query && mysql_num_rows($query)) {  
  7.         while($row = mysql_fetch_assoc($query)) {  
  8.             $data[] = $row;  
  9.         }  
  10.     } else {  
  11.         $data = [];  
  12.     }  
  13. ?>  
  14. <!DOCTYPE html>  
  15. <html lang="en">  
  16. <head>  
  17.     <meta charset="UTF-8">  
  18.     <title>文章发布系统</title>  
  19.     <meta name="keywords" content=""/>  
  20.     <meta name="description" content="文章发布系统"/>  
  21.     <link rel="stylesheet" href="default.css" type="text/css">  
  22. </head>  
  23. <body>  
  24.     <div id="wrapper">  
  25.         <div id="header">  
  26.             <div id="logo">  
  27.                 <h1><a href="#">php与mysql<sup></sup></a></h1>  
  28.                 <h2></h2>  
  29.             </div>  
  30.   
  31.             <div id="menu">  
  32.                 <ul>  
  33.                     <li class="active"><a href="article.list.php">文章</a></li>  
  34.                     <li><a href="about.php">关于我们</a></li>  
  35.                     <li><a href="contact.php">联系我们</a></li>  
  36.                 </ul>  
  37.             </div>  
  38.         </div>  
  39.     </div>  
  40.   
  41.     <div id="page">  
  42.         <div id="content">  
  43.             <?php  
  44.                 if(empty($data)) {  
  45.                     echo "当前没有文章,请管理员在后台添加文章";  
  46.                 } else {  
  47.                     foreach ($data as $value) {  
  48.             ?>  
  49.                   
  50.                 <div class="post">  
  51.                     <h1 class="title"><?php echo $value['title']; ?><span style="color:#CCC; font-size:14px;">  作者:<?php echo $value['author'];?></span></h1>  
  52.                     <div class="entry">  
  53.                         <?php echo $value['description']; ?>  
  54.                     </div>  
  55.                     <div class="meta">  
  56.                         <p class="links"><a href="article.show.php?id=<?php echo $value['id']; ?>" class="more">查看详细</a>  »  </p>  
  57.                     </div>  
  58.                 </div>  
  59.   
  60.             <?php  
  61.                     }  
  62.                 }  
  63.             ?>  
  64.         </div>  
  65.   
  66.         <div id="sidebar">  
  67.             <ul>  
  68.                 <li id="search">  
  69.                     <h2><b class="text1">Search</b></h2>  
  70.                     <form action="article.search.php" method="get">  
  71.                         <fieldset>  
  72.                             <input type="text" id="s" name="key" value="">  
  73.                             <input type="submit" id="x" value="Search">  
  74.                         </fieldset>  
  75.                     </form>  
  76.                 </li>  
  77.             </ul>  
  78.         </div>  
  79.   
  80.         <div style="clear: both;"> </div>  
  81.     </div>  
  82.   
  83.     <div id="footer">  
  84.         <p id="legal">Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved</p>  
  85.     </div>  
  86. </body>  
  87. </html>  
<?php
	require_once('connect.php');
	$key = $_GET['key'];
	$sql = "select * from article where title like '%$key%' order by dateline desc";
	$query = mysql_query($sql);
	if($query && mysql_num_rows($query)) {
		while($row = mysql_fetch_assoc($query)) {
			$data[] = $row;
		}
	} else {
		$data = [];
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>文章发布系统</title>
	<meta name="keywords" content=""/>
	<meta name="description" content="文章发布系统"/>
	<link rel="stylesheet" href="default.css" type="text/css">
</head>
<body>
	<div id="wrapper">
		<div id="header">
			<div id="logo">
				<h1><a href="#">php与mysql<sup></sup></a></h1>
				<h2></h2>
			</div>

			<div id="menu">
				<ul>
					<li class="active"><a href="article.list.php">文章</a></li>
					<li><a href="about.php">关于我们</a></li>
					<li><a href="contact.php">联系我们</a></li>
				</ul>
			</div>
		</div>
	</div>

	<div id="page">
		<div id="content">
			<?php
				if(empty($data)) {
					echo "当前没有文章,请管理员在后台添加文章";
				} else {
					foreach ($data as $value) {
			?>
				
				<div class="post">
					<h1 class="title"><?php echo $value['title']; ?><span style="color:#CCC; font-size:14px;">  作者:<?php echo $value['author'];?></span></h1>
					<div class="entry">
						<?php echo $value['description']; ?>
					</div>
					<div class="meta">
						<p class="links"><a href="article.show.php?id=<?php echo $value['id']; ?>" class="more">查看详细</a>  »  </p>
					</div>
				</div>

			<?php
					}
				}
			?>
		</div>

		<div id="sidebar">
			<ul>
				<li id="search">
					<h2><b class="text1">Search</b></h2>
					<form action="article.search.php" method="get">
						<fieldset>
							<input type="text" id="s" name="key" value="">
							<input type="submit" id="x" value="Search">
						</fieldset>
					</form>
				</li>
			</ul>
		</div>

		<div style="clear: both;"> </div>
	</div>

	<div id="footer">
		<p id="legal">Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved</p>
	</div>
</body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值