전체 코드를 보여주는 PHP 개발 메시지 보드
앞서 HTML 페이지, 페이징 및 표시 코드를 작성했습니다. 이제 원래 의도에 맞게 전체 코드를 하나의 페이지로 통합해야 합니다.
전체 코드
<?php
session_start();
header("content-type:text/html;charset=utf-8");
$page=isset($_GET['page']) ?$_GET['page'] :1 ;//接收页码
$page=!empty($page) ? $page :1;
$conn=mysqli_connect("localhost","root","root","Ressage");
mysqli_set_charset($conn,'utf8'); //设定字符集
$table_name="ressage_user";//查取表名设置
$perpage=5;//每页显示的数据个数
//最大页数和总记录数
$total_sql="select count(*) from $table_name";
$total_result =mysqli_query($conn,$total_sql);
$total_row=mysqli_fetch_row($total_result);
$total = $total_row[0];//获取最大页码数
$total_page = ceil($total/$perpage);//向上整数
//临界点
$page=$page>$total_page ? $total_page:$page;//当下一页数大于最大页数时的情况
//分页设置初始化
$start=($page-1)*$perpage;
$sql= "select * from ressage_user order by id desc limit $start ,$perpage";
$result=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>留言板</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<style>
/*#left{*/
/*width: 25%;*/
/*float: left;*/
/*}*/
/*#center{*/
/*width: 42%;*/
/*float: left;*/
/*}*/
/*#right{*/
/*width: 32%;*/
/*float: left;*/
/*}*/
.right{
margin-left: 140px;
}
.button{
background-color: rgba(230, 228, 236, 0.93); /* Green */
border: none;
color: #110c0f;
padding: 10px 70px;
text-align: center;
display: inline-block;
font-size: 16px;
margin-left: 20px;
cursor: pointer;
}
form{
font-size: 17px;
}
button{
background-color: rgba(249, 247, 255, 0);
border: none;
font-size: 16px;
color: #551a8b;
cursor: pointer;
}
a{
text-decoration:none;
}
table{
width: 360px;
height: 100px;
}
</style>
<script>
$(document).ready(function(){
$("button").click(function(){
$("form").toggle();
});
});
function foo(){
if(myform.name.value=="")
{
alert("请输入你的姓名");
myform.name.focus();
return false;
}
if (myform.content.value=="")
{
alert("留言内容不能为空");
myform.content.focus();
return false;
}
if(myform.vcode.value==""){
alert('验证码不能为空');
myform.vcode.focus();
return false;
}
}
</script>
</head>
<body>
<div id="left">
<img src="https://img.php.cn/upload/image/460/147/285/1477727203382106.jpg" width="370px">
</div>
<div id="center">
<h1>留言内容</h1>
<p>
<?
if($result==null){
echo"暂时没有留言";
} ?>
</p>
<?php
while($row=mysqli_fetch_array($result)){
?>
<table border="1" cellspacing="0">
<tr>
<td>姓名:<?php echo $row['name']?></td>
<td style="text-align: center">留言时间:<?php echo $row['ressage_time']?></td>
<td><a href="ressage_delete.php?id=<?php echo $row['id']?>" >删除</a> </td>
</tr>
<tr>
<td colspan="3">你的留言:<?php echo $row['content']?></td>
</tr>
</table>
<?php
}?>
<div id="baner" style="margin-top: 20px">
<a href="<?php
echo "$_SERVER[PHP_SELF]?page=1"
?>">首页</a>
<a href="<?php
echo "$_SERVER[PHP_SELF]?page=".($page-1)
?>">上一页</a>
<!-- 显示123456等页码按钮-->
<?php
for($i=1;$i<=$total_page;$i++){
if($i==$page){//当前页为显示页时加背景颜色
echo "<a style='padding: 5px 5px;background: #000;color: #FFF' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>";
}else{
echo "<a style='padding: 5px 5px' href='$_SERVER[PHP_SELF]?page=$i'>$i</a>";
}
}
?>
<a href="<?php
echo "$_SERVER[PHP_SELF]?page=".($page+1)
?>">下一页</a>
<a href="<?php
echo "$_SERVER[PHP_SELF]?page={$total_page}"
?>">末页</a>
<span>共<?php echo $total?>条</span>
</div>
</div>
<div id="right" >
<h2>留言板</h2>
<div > <a href="">首页</a> | <button>留言</button> <a href="" class="right">管理员登录</a>
<form method="post" action="ressage_post.php" style="display:none;" onsubmit="return foo();" name="myform" ">
<div class="form">
<p>
姓名:<input type="text" name="name">
</p>
<p>
邮箱:<input type="email" name="email">
</p>
<p>
留言内容:<br/>
<textarea cols="30" rows="7" name="content"></textarea>
</p>
<p>
验证码:<input type="text" name="vcode"><img src="yanzhengma.php" onClick="this.src='yanzhengma.php?nocache='+Math.random()" style="cursor:hand">
</p>
<p>
<button class="button">提交留言</button>
</p>
</div>
</form>
</div>
</body>
</html>위 코드는 HTML 페이지에 메시지를 게시하면 같은 페이지에 메시지가 표시됩니다. 콘텐츠가 페이지를 가득 채우면 페이징 효과가 나타납니다
오른쪽의 페이지 표시를 살펴보겠습니다. 각 메시지 뒤에 삭제 링크가 있습니다. 다음 한 장에 삭제 기능을 만들어 보겠습니다
새로운 파일
<head>
<meta charset="UTF-8">
<title>留言板</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<style>
/*#left{*/
/*width: 25%;*/
/*float: left;*/
/*}*/
/*#center{*/
/*width: 42%;*/
/*float: left;*/
/*}*/
/*#right{*/
/*width: 32%;*/
/*float: left;*/
/*}*/
.right{
margin-left: 140px;
}
.button{
background-color: rgba(230, 228, 236, 0.93); /* Green */
border: none;
color: #110c0f;
padding: 10px 70px;
text-align: center;
display: inline-block;
font-size: 16px;
margin-left: 20px;
cursor: pointer;
}
form{
font-size: 17px;
}
button{
background-color: rgba(249, 247, 255, 0);
border: none;
font-size: 16px;
color: #551a8b;
cursor: pointer;
}
a{
text-decoration:none;
}
table{
width: 360px;
height: 100px;
}
</style>
<script>
$(document).ready(function(){
$("button").click(function(){
$("form").toggle();
});
});
function foo(){
if(myform.name.value=="")
{
alert("请输入你的姓名");
myform.name.focus();
return false;
}
if (myform.content.value=="")
{
alert("留言内容不能为空");
myform.content.focus();
return false;
}
if(myform.vcode.value==""){
alert('验证码不能为空');
myform.vcode.focus();
return false;
}
}
</script>
</head>
<body>
<div id="left">
<img src="https://img.php.cn//upload/image/460/147/285/1477727203382106.jpg" width="370px">
</div>
<div id="center">
<h1>留言内容</h1>
<p>
</p>
<table cellspacing="0" border="1">
<tbody><tr>
<td>姓名:小龙</td><td style="text-align: center">留言时间:2016-11-02</td>
<td><a href="ressage_delete.php?id=14">删除</a> </td>
</tr>
<tr>
<td colspan="3">你的留言:小龙的身体特别棒</td>
</tr>
</tbody></table>
<table cellspacing="0" border="1">
<tbody><tr>
<td>姓名:小明</td><td style="text-align: center">留言时间:2016-11-02</td>
<td><a href="ressage_delete.php?id=13">删除</a> </td>
</tr>
<tr>
<td colspan="3">你的留言:小明的学习怎么样?</td>
</tr>
</tbody></table>
<table cellspacing="0" border="1">
<tbody><tr>
<td>姓名:刘奇</td><td style="text-align: center">留言时间:2016-11-02</td>
<td><a href="ressage_delete.php?id=12">删除</a> </td>
</tr>
<tr>
<td colspan="3">你的留言:今天你那里天气怎么样</td>
</tr>
</tbody></table>
<div id="baner" style="margin-top: 20px">
<a href="/ressage.php?page=1">首页</a>
<a href="/ressage.php?page=0">上一页</a>
<!-- 显示123456等页码按钮-->
<a style="padding: 5px 5px;background: #000;color: #FFF" href="/ressage.php?page=1">1</a> <a href="/ressage.php?page=2">下一页</a>
<a href="/ressage.php?page=1">末页</a>
<span>共3条</span>
</div>
</div>
<div id="right">
<h2>留言板</h2>
<div> <a href="">首页</a> | <button>留言</button> <a href="" class="right">管理员登录</a>
<form method="post" action="ressage_post.php" style="display:none;" onsubmit="return foo();" name="myform" "="">
<div class="form">
<p>
姓名:<input name="name" type="text">
</p>
<p>
邮箱:<input name="email" type="email">
</p>
<p>
留言内容:<br>
<textarea cols="30" rows="7" name="content"></textarea>
</p>
<p>
验证码:<input name="vcode" type="text"><img src="yanzhengma.php" onclick="this.src='yanzhengma.php?nocache='+Math.random()" style="cursor:hand">
</p>
<p>
<button class="button">提交留言</button>
</p>
</div>
</form>
</div>
</div></body>
시사
Clear
- 코스 추천
- 코스웨어 다운로드
현재 코스웨어를 다운로드할 수 없습니다. 현재 직원들이 정리하고 있습니다. 앞으로도 본 강좌에 많은 관심 부탁드립니다~
이 강좌를 시청한 학생들도 학습하고 있습니다.
PHP로 사업을 시작하는 방법에 대해 간단히 이야기해 보겠습니다.
웹 프론트 엔드 개발에 대한 빠른 소개
민망한 물건 백과사전 사이트를 모방한 Mini 버전 MVC 프레임워크의 대규모 실용 Tianlongbabu 개발
PHP 실용 개발 시작하기: 빠른 PHP 생성 [중소기업 포럼]
로그인 인증 및 클래식 게시판
컴퓨터 네트워크 지식 수집
빠른 시작 Node.JS 정식 버전
당신을 가장 잘 이해하는 프론트엔드 강좌: HTML5/CSS3/ES6/NPM/Vue/...[원본]
자신만의 PHP MVC 프레임워크 작성(깊이 있는 40개 장/자세한 내용/초보자가 발전하려면 읽어야 함)
















