- css
样式文件 - database
- images
图像切片文件夹,除了check字样的后台处理php文件,其余php文件都需要导入图像的各个切片,并且采用表格布局形式 - menu.php
图像热点导航栏模块,以下每个文件模块需导入
<table width="202" border="0">
<tbody>
<tr>
<td height="34" width="202" background="images/image_03.gif"></td>
</tr>
<tr>
<td height="310" width="202" ><img src="images/image_09.gif" alt="" width="202" height="310" usemap="#Map" border="0"/></td>
</tr>
</tbody>
</table>
<map name="Map">
<area shape="rect" coords="8,38,198,68" href="add.php">
<area shape="rect" coords="8,67,197,94" href="search.php">
<area shape="rect" coords="9,94,197,117" href="page.php">
<area shape="rect" coords="8,118,195,143" href="update.php">
<area shape="rect" coords="10,142,194,166" href="delete.php">
</map>
- index.php
索引文件,通过图像热点的形式链接到各个功能模块
<html>
<head>
<title>电子公告管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td bgcolor="#F0F0F0" width="202" rowspan="3" valign="top"><?php include("menu.php");?></td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top"><table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif">
<table width="600" height="257" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"> </td>
</tr>
<tr>
<td height="235" align="center" valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
</body>
</html>
- db_conn.php
数据库链接模块,所有check字样的php文件都需要导入该模块
<?php
$conn=mysqli_connect("localhost","root","root") or die("数据库服务器连接错误".mysqli_error());//连接MySQL
mysqli_select_db($conn,"bulletin_board") or die("数据库访问错误".mysqli_error());//选择数据库
mysqli_query($conn, "set names utf8"); //设置查询结果集的字符编码
?>
- add.php->check_add.php
添加公告模块
add.php前台
<html>
<head>
<title>公告信息管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script>
function check(form){
if(form.txt_title.value==""){
alert("请输入公告标题!");form.txt_title.focus();return false;
}
if(form.txt_content.value==""){
alert("请输入公告内容!");form.txt_content.focus();return false;
}
form.submit();
}
</script>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td width="202" rowspan="3" valign="top"><?php include("menu.php");?></td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top"><table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif">
<table width="600" height="257" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"><strong>添加公告信息</strong></td>
</tr>
<tr>
<td height="235" align="center" valign="top"><table width="500" height="226" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="226" align="center" valign="top">
<form name="form1" method="post" action="check_add.php">
<table width="520" height="212" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="87" align="center">公告主题:</td>
<td width="433" height="31"><input name="txt_title" type="text" id="txt_title" size="40">
* </td>
</tr>
<tr>
<td height="124" align="center">公告内容:</td>
<td><textarea name="txt_content" cols="50" rows="8" id="txt_content"></textarea></td>
</tr>
<tr>
<td height="40" colspan="2" align="center">
<input name="Submit" type="submit" value="保存" onClick="return check(form1);">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
</body>
</html>
check_add.php后台
<?php
include_once("db_conn.php"); //导入数据库连接文件
$title=$_POST['txt_title']; //获取标题信息
$content=$_POST['txt_content']; //获取内容信息
$createtime=date("Y-m-d H:i:s"); //设置插入时间
$sql=mysqli_query($conn, "insert into tb_board(title,content,createtime) values('$title','$content','$createtime')"); //执行插入操作
if($sql){
echo "<script>alert('公告添加成功');window.location.href='add.php';</script>";
}
mysqli_free_result($sql); //关闭记录集
mysqli_close($conn); //关闭数据库连接
?>
<meta charset="utf-8">
- search.php
查询公告模块
<html>
<head>
<title>电子公告管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script>
function check(form){
if(form.txt_keyword.value==""){
alert("请输入查询关键字!");form.txt_keyword.focus();return false;
}
form.submit();
}
</script>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td bgcolor="#F0F0F0" width="202" rowspan="3" valign="top"><?php include("menu.php");?></td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top"><table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif"><table width="600" height="271" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"><strong>查询公告信息</strong></td>
</tr>
<tr>
<td height="249" align="center" valign="top">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="center">
<form name="form1" method="post" action="">
查询关键字
<input name="txt_keyword" type="text" id="txt_keyword" size="40">
<input type="submit" name="Submit" value="搜索" onClick="return check(form)">
</form>
</td>
</tr>
</table>
<?php
if ( isset( $_POST['txt_keyword'] ) )
{
include_once("db_conn.php");
$keyword=$_POST['txt_keyword'];
$sql=mysqli_query($conn,"select * from tb_board where title like '%$keyword%' or content like '%$keyword%'");//模糊查询
$row=mysqli_fetch_object($sql);
if(!$row)
{
echo "<font color='red'>您搜索的信息不存在,请使用类似的关键字进行检索!</font>";
}
else
{
?>
<table class="table">
<tr>
<th width="221">公告标题</th>
<th width="329">公告内容</th>
</tr>
<?php
do
{
?>
<tr bgcolor="#FFFFFF">
<td>
<div style="overflow-y:scroll;height:60px;white-space:pre-wrap">
<?php echo $row->title;?>
</div>
</td>
<td>
<div style="overflow-y:scroll;height:60px;white-space:pre-wrap">
<?php echo $row->content;?>
</div>
</td>
</tr>
<?php
}
while($row=mysqli_fetch_object($sql));
mysqli_free_result($sql);
mysqli_close($conn);
?>
</table>
<?php
}
}
?></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
</body>
</html>
- update.php->modify.php->check_modify.php
更新公告模块
update.php
<html>
<head>
<title>公告信息管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script>
function check(form){
if(form.txt_keyword.value=="")
{
alert("请输入查询关键字!");form.txt_keyword.focus();return false;
}
form.submit();
}
</script>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td width="202" rowspan="3" valign="top" bgcolor="#F0F0F0">
<table width="202" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include("menu.php");?></td>
</tr>
</table>
</td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top">
<table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif">
<table width="600" height="271" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"><strong>编辑公告信息</strong></td>
</tr>
<tr>
<td height="249" align="center" valign="top"><table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="center">
<form name="form1" method="post" action="">
查询关键字
<input name="txt_keyword" type="text" id="txt_keyword" size="40">
<input type="submit" name="Submit" value="搜索" onClick="return check(form)">
</form>
</td>
</tr>
</table>
<table class="table">
<tr>
<th width="214">公告标题</th>
<th width="271">公告内容</th>
<th width="47">编辑</th>
</tr>
<?php
include_once("db_conn.php");
if ( isset( $_POST["txt_keyword"] ) ){
$keyword=$_POST["txt_keyword"];
$sql=mysqli_query($conn, "select * from tb_board where title like '%$keyword%' or content like '%$keyword%'");
}
else{
$sql=mysqli_query($conn, "select * from tb_board");
}
$row=mysqli_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无公告信息!</font>";
}
do{
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $row->title;?></td>
<td><?php echo $row->content;?></td>
<td align="center"><a href="modify.php?id=<?php echo $row->id;?>"><img src="images/update.gif" width="20" height="18" border="0"></a></td>
</tr>
<?php
}while($row=mysqli_fetch_object($sql));
mysqli_free_result($sql);
mysqli_close($conn);
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
</body>
</html>
modify.php
<html>
<head>
<title>电子公告管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script>
function check(form){
if(form.txt_title.value==""){
alert("公告标题不能为空!");form.txt_title.focus();return false;
}
if(form.txt_content.value==""){
alert("公告内容不能为空!");form.txt_content.focus();return false;
}
form.submit();
}
</script>
<?php
if (!isset( $_GET["id"] ) ){
//echo"<script>alert('你没有选择操作记录。');history.go(-2);<//script>";
echo"<script>alert('你没有选择操作记录。');</script>";
}
else{
include_once("db_conn.php");
$id=$_GET["id"];
$sql=mysqli_query($conn,"select * from tb_board where id=$id");
$row=mysqli_fetch_object($sql);
?>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td bgcolor="#F0F0F0" width="202" rowspan="3" valign="top"><?php include("menu.php");?></td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top"><table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif">
<table width="600" height="257" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"><strong>编辑公告信息</strong></td>
</tr>
<tr>
<td height="235" align="center" valign="top"><table width="500" height="226" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="226" align="center" valign="top"><form name="form1" method="post" action="check_modify.php">
<table width="520" height="212" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="87" align="center">公告主题:</td>
<td width="433" height="31">
<input name="txt_title" type="text" id="txt_title" size="40" value="<?php echo $row->title;?>">
<input name="id" type="hidden" value="<?php echo $row->id;?>">
</td>
</tr>
<tr>
<td height="124" align="center">公告内容:</td>
<td>
<textarea name="txt_content" cols="50" rows="8" id="txt_content"><?php echo $row->content;?></textarea>
</td>
</tr>
<tr>
<td height="40" colspan="2" align="center">
<input name="Submit" type="submit" value="修改" onClick="return check(form1);">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
<?php
}
?>
</body>
</html>
check_modify.php
<meta charset="utf-8">
<?php
include_once("db_conn.php");
$title=$_POST["txt_title"];
$content=$_POST["txt_content"];
$id=$_POST["id"];
$sql=mysqli_query($conn,"update tb_board set title='$title',content='$content' where id=$id");
if($sql){
//echo "<script>alert('公告信息编辑成功!');history.back();window.location.href='modify.php?id=$id';<//script>";
header("Location:update.php");
}else{
echo "<script>alert('公告信息编辑失败!');history.back();window.location.href='modify.php?id=$id';</script>";
}
?>
- delete.php->check_del.php
删除公告模块
delete.php
<html>
<head>
<title>公告信息管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script>
function check(form){
if(form.txt_keyword.value==""){
alert("请输入查询关键字!");form.txt_keyword.focus();
return false;
}
form.submit();
}
</script>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td width="202" rowspan="3" valign="top" bgcolor="#F0F0F0">
<table width="202" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include("menu.php");?></td>
</tr>
</table>
</td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top"><table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif">
<table width="600" height="271" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"><strong>编辑公告信息</strong></td>
</tr>
<tr>
<td height="249" align="center" valign="top">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="center"><form name="form1" method="post" action="">
查询关键字
<input name="txt_keyword" type="text" id="txt_keyword" size="40">
<input type="submit" name="Submit" value="搜索" onClick="return check(form)">
</form>
</td>
</tr>
</table>
<table class="table">
<tr>
<th width="214">公告标题</th>
<th width="271">公告内容</th>
<th width="47">编辑</th>
</tr>
<?php
include_once("db_conn.php");
if ( isset( $_POST["txt_keyword"] ) ){
$keyword=$_POST["txt_keyword"];
$sql=mysqli_query($conn,"select * from tb_board where title like '%$keyword%' or content like '%$keyword%'");
}
else{
$sql=mysqli_query($conn,"select * from tb_board");
}
$row=mysqli_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无公告信息!</font>";
}
do{
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $row->title;?></td>
<td><?php echo $row->content;?></td>
<td align="center">
<a href="check_del.php?id=<?php echo $row->id;?>"><img src="images/delete.gif" width="22" height="22" border="0"></a>
</td>
</tr>
<?php
}while($row=mysqli_fetch_object($sql));
mysqli_free_result($sql);
mysqli_close($conn);
?>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
</body>
</html>
check_del.php
<meta charset="utf-8">
<?php
include_once("db_conn.php");
$id=$_GET["id"];
$sql=mysqli_query($conn, "delete from tb_board where id=$id");
if($sql){
echo "<script>history.back();window.location.href='delete.php?id=$id';</script>";
}else{
echo "<script>alert('公告信息删除失败!');history.back();window.location.href='delete.php?id=$id';</script>";
}
?>
- page.php
分页显示模块
<html>
<head>
<title>公告信息管理</title>
<meta charset="utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="828" height="385" border="0" align="center" cellpadding="0" cellspacing="0" id="__01">
<tr>
<td width="202" rowspan="3" valign="top"><table width="202" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include("menu.php");?></td>
</tr>
</table></td>
<td height="34" background="images/image_04.gif"> </td>
</tr>
<tr>
<td height="38" background="images/image_06.gif"> </td>
</tr>
<tr>
<td height="270" valign="top"><table width="626" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="257" align="center" valign="top" background="images/image_08.gif"><table width="600" height="271" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="22" align="center" valign="top" class="word_orange"><strong>公告信息<strong>分页显示</strong></strong></td>
</tr>
<tr>
<td height="249" align="center" valign="top"><table class="table">
<tr>
<th width="221">公告标题</th>
<th width="329">公告内容</th>
</tr>
<?php
include_once("db_conn.php");
/* $page为当前页,如果$page为空,则初始化为1 */
if ( isset( $_GET["page"] ) )
$page = $_GET["page"];
else
$page = "";
if ($page==""){
$page=1;}
if (is_numeric($page)){
$page_size=5; //每页显示5条记录
$query="select count(*) as total from tb_board order by id desc";
$result=mysqli_query($conn, $query); //查询符合条件的记录总条数
$message_count=mysqli_fetch_array($result); //获取当前记录
$message_count=$message_count[0]; //要显示的总记录数
$page_count=ceil($message_count/$page_size); //根据记录总数除以每页显示的记录数求出所分的页数
$offset=($page-1)*$page_size; //计算下一页从第几条数据开始循环
$sql=mysqli_query($conn, "select * from tb_board order by id desc limit $offset, $page_size");
$row=mysqli_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无公告信息!</font>";
}
do{
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $row->title;?></td>
<td><?php echo $row->content;?></td>
</tr>
<?php
}while($row=mysqli_fetch_object($sql));
}
?>
</table>
<br>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<!-- 翻页条 -->
<td width="37%"> 页次:<?php echo $page;?>/<?php echo $page_count;?>页 记录:<?php echo $message_count;?> 条 </td>
<td width="63%" align="right"><?php
/* 如果当前页不是首页 */
if($page!=1){
/* 显示“首页”超链接 */
echo "<a href=page.php?page=1>首页</a> ";
/* 显示“上一页”超链接 */
echo "<a href=page.php?page=".($page-1).">上一页</a> ";
}
/* 如果当前页不是尾页 */
if($page<$page_count){
/* 显示“下一页”超链接 */
echo "<a href=page.php?page=".($page+1).">下一页</a> ";
/* 显示“尾页”超链接 */
echo "<a href=page.php?page=".$page_count.">尾页</a>";
}
mysqli_free_result($sql);
mysqli_close($conn);
?>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#F0F0F0"></td>
<td height="43" background="images/image_12.gif"></td>
</tr>
</table>
</body>
</html>
浏览器输出效果:
附录:导入MySQL数据库
- 法一:将database文件夹中的bulletin_board文件夹导入到MySQL安装目录下的data文件夹中
- 法二:进入MySQL数据库管理系统,利用命令行或者phpmyadmin等图形工具导入bulletin_board.sql(导入之前先创建名为bulletin_board的数据库)