登录前端页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录页面</title>
</head>
<script src="../base/jquery-3.4.1.min.js"></script>
<style>
fieldset{width: 300px;
height: 400px;
position:absolute;
right: 20%;
border: 1px solid rgb(94, 94, 94);
border-radius: 5px;
box-shadow: 0 0 8px rgb(19, 17, 59);
background-color: #f0f0f0b0;
top: 100px;
}
body{
background-image: url(../tupian/登入背景页面.jpg);
}
h1{
font-size: 50px;
text-align: center;
font-family:楷体 ;
}
#username{
font-size: 20px;
border-radius: 5px;
border: 1px solid rgb(125, 125, 125);
}
#paw{
font-size: 20px;
border-radius: 5px;
border: 1px solid rgb(125, 125, 125);
}
#yan{
border-radius: 5px;
border: 1px solid rgb(125, 125, 125);
width: 100px;
display: inline-block; vertical-align:bottom;
}
#an{
font-size: 19px;
background-color: rgba(8, 189, 253);
color: #fff;
width: 300px;
height: 40px;
border-radius: 6px;
border: none;
}
#canvas{border: 1px solid;
width: 100px;
height: 50px;
display: inline-block; vertical-align: top;
}
a{
text-decoration: none;
font-size: 12px;
}
span{
font-size: 12px;
}
</style>
<body>
<fieldset>
<h1>登 录</h1>
<p><input type="text"
name="user"
id="username" placeholder="账号"></p>
<input type="password" name="pass" id="paw" placeholder="密码">
<p></p>
<p></p><input type="button" id="an" value="登录" onclick="fun()" >
<span>没有账户?</span><a href="./reg.html">点击注册</a>
</fieldset>
</body>
<script>
function fun(){
var user=$('#username').val();
var password=$('#paw').val();
// alert(user+password);
if (user==""||password=="") {
alert("请按规则填写")
}else{
var date="user="+user+"&password="+password;
$.post(
'enter.php',
date,
function(date){
alert(date);
if (date=='登入成功') {
location.href='home new.php';
}else{
location.href='enter.html';
}
}
)
}
}
</script>
</html>
登录页面后端
<?php
session_start();
$user=$_POST['user'];
$password=$_POST['password'];
include '../blog/dp.php'; #是引用的PHP文件用于数据库连接
$sql="select * from blog.users where username='$user' and password='$password'";
$num=dql_nums($sql);
if($num==1){
//定制session文件
$_SESSION['username']=$user; //判断登录文件,进行保存
$_SESSION['isLogin']=true;
echo '登入成功';
// echo "<script>location.href='home.php'</script>";
}
else{
echo '登入失败';
// echo "<script>location.href='enter.html'</script>";
}
?>
注册页面前端
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>注册页面</title>
</head>
<script src="../base/jquery-3.4.1.min.js"></script>
<style>
fieldset{width: 400px;
height: 600px;
position:absolute;
right: 120px;
top: 100px;
text-align: center;
border: 1px solid rgb(121, 121, 121);
border-radius: 10px;
box-shadow: 0 0 8px rgb(74, 74, 74);
background-color: #f0f0f0b5;
}
body{
background-image:url(../tupian/注册页面.jpg);
}
fieldset input{
border: 1px solid rgb(121, 121, 121);
width: 200px;
height: 25px;
border-radius:8px;
}
fieldset label {
display: inline-block;
vertical-align: middle;
width: 100px;
text-align:left;
}
fieldset input[type="text"] {
display: inline-block;
vertical-align:middle;
width: 200px;
height: 25px;
border-radius: 8px;
}
span{
font-size:10px;
}
</style>
<body>
<fieldset>
<h1 for="">欢迎注册</h3><br>
<label for="username">用户名:</label><input type="text" name="username" id="user"><br>
<p></p>
<br>
<label for="password">密码:</label><input type="password" name="password" id="passd" ><br>
<p></p>
<br>
<label for="passwords">确认密码:</label><input type="password" name="passwords" id="passds" ><br>
<p></p>
<br>
<label for="tel">手机号:</label><input type="tel" id="tel" name="tel"><br>
<p></p>
<br>
<input type="button" value="注册" onclick="fn()" style="width:300px;height:40px;background-color: rgba(203, 247, 250, 0.937);">
<br>
<p></p>
<input type="checkbox" name="text" id="text" style="width: 15px;height:15px;"><span>阅读并接受<a href="https://www.4399.com/" style="text-decoration: none;font-size:10px;">《论坛用户协议》</a>、<a href="https://www.4399.com/" style="text-decoration: none;font-size:10px;">《儿童个人信息保护声明》</a>及<a href="https://www.4399.com/" style="text-decoration: none;font-size:10px;">《论坛隐私权保护声明》</a></span>
<p></p>
<br>
<span>已经有账户了?</span><a href="enter.html" style="text-decoration: none;font-size:10px;">欢迎登入</a>
</fieldset>
</body>
</html>
JS部分
<script>
function fn() {
var user=$('#user').val();
var passd=$('#passd').val();
var passds=$('#passds').val();
var tel=$('#tel').val();
var text=$('#text');
// 使用var的方式通过函数提交前端的数据
if (!text.is(":checked")){
alert("没有同意用户协议"); //对复选框进行判断
}else{
if (passd!=passds) {
alert("前后密码不一致") //对前后密码进行判断
}else{
var pant=/1[3-9][0-9]{9}/;
if (!pant.test(tel)) {
alert("不是正确手机号码"); //对注册手机号判断
}else{
if ((user=="")||(passd=="")) {
alert("用户名或者密码不能为空"); //防止空,其实最好是写在后端,前端的安全验证都是不安全的,可以随便绕过进行攻击
}else{
var data="user="+user+"&passd="+passd+"&tel="+tel;
$.post(
'reg.php',
data,
function(data){
alert(data);
location.href='home new.php';
}
)
}
}
}
}
}
</script>
注册页面后端
<?php
$user = $_POST['user'];
$passd = $_POST['passd'];
$tel = $_POST['tel'];
// echo $user.$passd.$tel;
include "../blog/dp.php";
$sql="select * from blog.users where username='$user'"; //将$sql引用进去
$num=dql_nums($sql); //dql_nums返回一个值由$num接受
//根据数据库返回信息执行
if($num==1){
die ('该用户名以存在');
}
$sql="select * from blog.users where tel='$tel'";
$num1=dql_nums($sql);
if ($num1==1) {
die ('该手机号码已注册');
}
$sql="insert into users(username,password,tel) values('$user','$passd','$tel')";
$num2=mysql_dml($sql);
if ($num2==1) {
echo '注册成功';
}
?>
发帖功能后端
<?php
$title=$_POST['title'];
$word=$_POST['word'];
$sele=$_POST['sele'];
// echo $title.$word.$sele;
include '../blog/dp.php';
$sql="insert blog.ther(title,content,area) values('$title','$word','$sele') ;";
$num=mysql_dml($sql);
if ($num==1) {
echo '发表成功';
}
?>
回帖功能后端
<?php
$word=$_POST['word'];
$ther_id=$_POST['ther_id'];
// echo $word.$ther_id;
include '../blog/dp.php';
$sql="insert blog.rep(ther_id,content) values('$ther_id','$word');"; //通过外键和帖子id绑定来确定应该放置在哪
$num=mysql_dml($sql);
if ($num==1) {
echo '回复成功';
}
发送区域帖子的概况后端port
<?php
session_start();
if(@$_SESSION['isLogin']!=1){
die ("未登入");
}
include '../blog/dp.php';
$sql="select * from blog.ther;";
$res= dql_datail($sql);
echo json_encode($res);
?>
发送帖子回复区的后端port2
<?php
session_start();
if(@$_SESSION['isLogin']!=1){
die ("未登入");
}
include '../blog/dp.php';
$sql="select * from blog.rep;";
$res= dql_datail($sql);
echo json_encode($res);
?>
发送帖子回复区的后端port3
<?php
include '../blog/dp.php';
$sql="select ther_id,count(ther_id) from rep GROUP BY ther_id;";
$num= dql_datail($sql);
echo json_encode($num);
?>
点击帖子详情展示
<?php
session_start();
if(@$_SESSION['isLogin']!=1){
die ("未登入");
} //判断是否登录
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>内容</title>
</head>
<style>
body{
background-image: url(../tupian/R-C.png);
background-size: 100%;
}
.pull{border: 1px solid;
width: 40%;
margin: auto;
border-radius: 15px;
background-color: white;
}
.pull div{
border: 1px solid;
margin: 10px;
border-radius: 5px;
}
#content{
height: 80px;
}
#show{
color: blue;
border: none;
text-align: right;
}
#block {
width: 400px;
margin: 0 auto;
background-color: #f4f4f4;
padding: 20px;
display: none;
}
#time{
border: none;
font-size: 1px;
text-align: right;
color: #ccc;
}
</style>
<script src="../base/jquery-3.4.1.min.js"></script>
<body onload="port()">
<div class="pull">
<?php
include '../blog/dp.php';
$id=$_GET['id']; //获取get的id
$sql="select title,content,id,time from blog.ther where id=$id"; //根据帖子id查询帖子内容
$result=dql_datail($sql);
// print_r($result[0]);
// echo $result[0]['title'];
?>
<h1 style="text-align: center;"><?php echo $result[0]['title'] ?></h1>
<div id="time"><?php echo $result[0]['time'] ?></div>
<div id="content"><?php echo $result[0]['content'] ?></div>
<!-- 根据标题展示不同内容 -->
<div id="out">
<b>评论区</b>
<!-- <div>说的</div> -->
</div>
<div id="show" onclick="show()">[回复帖子]</div>
</div>
<!-- 回帖功能点击启用 -->
<div id="block">
<textarea name="" id="word" cols="30" rows="10"></textarea>
<input type="button" value="回复" onclick="pub()">
</div>
</body>
<script>
function show(){
if (document.getElementById("block").style.display=="none") {
document.getElementById("block").style.display="block";
} //判断原本属性的是否为隐藏状态,进行转换
else{
document.getElementById("block").style.display="none";
}
}
function pub(){ //回复功能
var word=$('#word').val();
var ther_id="<?php echo $id; ?>"
// alert(word+ther_id);
if (word=="") {
alert(内容不能为空)
}else{
var data="word="+word+"&ther_id="+ther_id;
$.post(
'rep.php',
data,
function(data){
alert(data);
window.location.reload();
}
)
}
}
var num=0; //设置原本数值为0
function port(){
$.get('port2.php',(data)=>{
// alert(data);
var da=eval(data);
var id=<?php echo $id; ?>
// alert(da);
da.forEach((d) => {if(d.ther_id==id){ //后台传递过来的数值进行遍历,将回帖的ther_id和主贴的id进行对比,相同的则进行展示
num++ //通过num进行楼层叠加
var word=d['content'];
var con=`<div>${num}楼:${word}</div>`
$('#out').append(con);
}
})
})
}
</script>
</html>
讨论区前端,和其它区域共享port后端,获取数据,进行展示
<?php
session_start();
if(@$_SESSION['isLogin']!=1){
die ("未登入");
}
// 对登录进行判断
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>论坛</title>
<style type="text/css">
/*对网页进行第二次修饰*/
body{font-size: 12px;
}
/*对整个标签,和表格 设置宽度为990像素*/
#discuss,#discuss-datas{
width: 990px;
margin: auto;
}
#discuss div.mt{
/*高度,边框,背景*/
height: 30px;
border: 1px solid #DDDDDD;
border-top: 2px solid #999999;
background: #f7f7f7;
}
#discuss-content{
border-bottom: 1px solid #DDDDDD;
}
#discuss-datas tr.header td{
/*加粗 上下内边距 下边框*/
font-weight: bold;
padding: 5px 0;
border-bottom: 1px solid #DDDDDD;
color: #666666;
}
#discuss-datas td{
/*内容水平居中对齐*/
text-align: center;
}
#discuss-datas td.col1{
/*宽度,文本左对齐*/
width: 620px;
text-align: left;
}
#discuss-datas tbody td{
/*文本颜色*/
color: #9c9c9c;
}
#discuss a{
/*改链接颜色 去掉下划线*/
text-decoration: none;
color: #005aa0;
}
#discuss a:hover{
text-decoration: underline;
}
#discuss-datas tbody td{
/*上下内边距 下边框*/
padding: 5px 0px;
border-bottom: 1px dotted #DDDDDD;
}
/*给论坛内容加标签 加图标*/
#discuss i{
/*左内边距 下内边距高度 背景图*/
padding-left: 21px;
padding-bottom: 5px;
background:url(img/c63802c9ee7e4ddec0e53e152e665ea.png) no-repeat;
background-size: 100%;
}
#discuss div.mt a{
float:left;
width: 100px;
height: 30px;
text-align: center;
line-height: 30px;
}
#discuss div.mt a:hover{
text-decoration: none;
color: #E4393C;
}
#discuss div.mt a.current{
border: 1px solid #DDDDDD;
border-top: 2px solid #E4393C;
border-bottom: 0;
background: #ffffff;
margin-top: -6px;
height: 35px;
line-height: 35px;
color: #E4393C;
}
#search{
float: right;
}
#show{
color: blue;
}
#block {
width: 400px;
margin: 0 auto;
background-color: #f4f4f4;
padding: 20px;
display: none;
}
#block label {
font-size: 18px;
color: #333;
}
#block input[type="text"], #block textarea {
width: 100%;
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block select {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block input[type="button"] {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
</style>
<script src="../base/jquery-3.4.1.min.js"></script>
</head>
<body onload="port()">
<!--论坛div-->
<div id="discuss">
<!--页签菜单栏-->
<div class="mt">
<a href="home hot.php">热度贴</a>
<a href="home new.php">新发帖</a>
<a href="home dis.php" class="current">讨论区</a>
<a href="home wat.php" >灌水区</a>
</div>
<!--讨论内容-->
<div id="discuss-content">
<!--表格内容-->
<table id="discuss-datas">
<!--标题栏-->
<tr class="header">
<td class="col1">主题</td>
<!-- <td>作者</td> -->
<td>时间</td>
</tr>
<!--内容栏-->
<tbody id="out">
</tbody>
</table>
<!--显示的拓展内容-->
<div id="discuss-total">
<div class="new_discuss" align="right">
有问题要与其他用户讨论
<div id="show" onclick="show()">[发表帖子]</div>
<div id="block">
<label for="">标题:</label>
<input type="text" id="title"><br>
<textarea name="" id="word" cols="30" rows="10"></textarea>
<select name="" id="sele">
<option value="dis">讨论区</option>
<option value="wat">灌水区</option>
</select>
<input type="button" value="发表" onclick="pub()">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
讨论区JS
function show(){
if (document.getElementById("block").style.display=="none") {
document.getElementById("block").style.display="block";
} //判断原本属性的是否为隐藏状态,进行转换
else{
document.getElementById("block").style.display="none";
}
}
function pub(){ //发帖功能
var title=$('#title').val();
var word=$('#word').val();
var sele=$('#sele').val();
// alert(title+word+sele);
if (title=="") {
alert('标题不能为空')
}else{
if (word=="") {
alert('内容不能为空')
}else{
var data="title="+title+"&word="+word+"&sele="+sele;
$.post(
'pub.php',
data,
function(data){
alert(data);
location.href='home dis.php';
}
)
}
}
}
function port(){ //获取mysql里的数据
$.get('port.php',(data)=>{
// alert(data);
var da=eval(data);
// alert(da);
da.forEach(d => {if(d.area=='dis'){ //设置if条件判断键值
var title=d['title']
var time=d['time']
var content=d['content']
var id=d['id']
var area=d['area']
//根据键获取值
var con=`<tr>
<td class="col1">
<i class="sheng"></i>
<a href="./vies.php?id=${id}">${title}</a>
</td>
<td>${time}</td>
</tr>`
$('#out').append(con); //将样式添加到指定地方进行展示
}
})
})
}
热度区域,和其它区域共享port后端,获取数据,进行展示,同时获取port3,获取回帖数量,进行排序
<?php
session_start();
if (@$_SESSION['isLogin'] != 1) {
die("未登入");
}
// 对登录进行判断
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>论坛</title>
<style type="text/css">
/*对网页进行第二次修饰*/
body {
font-size: 12px;
}
/*对整个标签,和表格 设置宽度为990像素*/
#discuss,
#discuss-datas {
width: 990px;
margin: auto;
}
#discuss div.mt {
/*高度,边框,背景*/
height: 30px;
border: 1px solid #DDDDDD;
border-top: 2px solid #999999;
background: #f7f7f7;
}
#discuss-content {
border-bottom: 1px solid #DDDDDD;
}
#discuss-datas tr.header td {
/*加粗 上下内边距 下边框*/
font-weight: bold;
padding: 5px 0;
border-bottom: 1px solid #DDDDDD;
color: #666666;
}
#discuss-datas td {
/*内容水平居中对齐*/
text-align: center;
}
#discuss-datas td.col1 {
/*宽度,文本左对齐*/
width: 620px;
text-align: left;
}
#discuss-datas tbody td {
/*文本颜色*/
color: #9c9c9c;
}
#discuss a {
/*改链接颜色 去掉下划线*/
text-decoration: none;
color: #005aa0;
}
#discuss a:hover {
text-decoration: underline;
}
#discuss-datas tbody td {
/*上下内边距 下边框*/
padding: 5px 0px;
border-bottom: 1px dotted #DDDDDD;
}
/*给论坛内容加标签 加图标*/
#discuss i {
/*左内边距 下内边距高度 背景图*/
padding-left: 21px;
padding-bottom: 5px;
background: url(img/c63802c9ee7e4ddec0e53e152e665ea.png) no-repeat;
background-size: 100%;
}
#discuss div.mt a {
float: left;
width: 100px;
height: 30px;
text-align: center;
line-height: 30px;
}
#discuss div.mt a:hover {
text-decoration: none;
color: #E4393C;
}
#discuss div.mt a.current {
border: 1px solid #DDDDDD;
border-top: 2px solid #E4393C;
border-bottom: 0;
background: #ffffff;
margin-top: -6px;
height: 35px;
line-height: 35px;
color: #E4393C;
}
#search {
float: right;
}
#show {
color: blue;
}
#block {
width: 400px;
margin: 0 auto;
background-color: #f4f4f4;
padding: 20px;
display: none;
}
#block label {
font-size: 18px;
color: #333;
}
#block input[type="text"],
#block textarea {
width: 100%;
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block select {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block input[type="button"] {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
</style>
<script src="../base/jquery-3.4.1.min.js"></script>
</head>
<body onload="port()">
<!--论坛div-->
<div id="discuss">
<!--页签菜单栏-->
<div class="mt">
<a href="home hot.php" class="current">热度贴</a>
<a href="home new.php">新发帖</a>
<a href="home dis.php">讨论区</a>
<a href="home wat.php">灌水区</a>
</div>
<!--讨论内容-->
<div id="discuss-content">
<!--表格内容-->
<table id="discuss-datas">
<!--标题栏-->
<tr class="header">
<td class="col1">主题</td>
<!-- <td>作者</td> -->
<td>时间</td>
</tr>
<!--内容栏-->
<tbody id="out">
</tbody>
</table>
<!--显示的拓展内容-->
<div id="discuss-total">
<div class="new_discuss" align="right">
有问题要与其他用户讨论
<div id="show" onclick="show()">[发表帖子]</div>
<div id="block">
<label for="">标题:</label>
<input type="text" id="title"><br>
<textarea name="" id="word" cols="30" rows="10"></textarea>
<select name="" id="sele">
<option value="dis">讨论区</option>
<option value="wat">灌水区</option>
</select>
<input type="button" value="发表" onclick="pub()">
</div>
</div>
</div>
</div>
</div>
</body>
<script>
</script>
</html>
热度区JS
function show() {
if (document.getElementById("block").style.display == "none") {
document.getElementById("block").style.display = "block";
} //判断原本属性的是否为隐藏状态,进行转换
else {
document.getElementById("block").style.display = "none";
}
}
function pub() {
var title = $('#title').val();
var word = $('#word').val();
var sele = $('#sele').val();
// alert(title+word+sele);
if (title == "") {
alert('标题不能为空')
} else {
if (word == "") {
alert('内容不能为空')
} else {
var data = "title=" + title + "&word=" + word + "&sele=" + sele;
$.post(
'pub.php',
data,
function(data) {
alert(data);
location.href = 'home hot.php';
}
)
}
}
}
var arr = [];
function port() {
$.get('port3.php', (data2) => { //通过port3传递回帖数量
// alert(data2)
var data2 = eval(data2);
arr = data2
// console.log(data2);
});
$.get('port.php', (data) => {
// alert(data);
var da = eval(data);
// alert(da);
da.forEach(item => {
arr.forEach(i => {
if (i.ther_id == item.id) {
item['count(ther_id)'] = i['count(ther_id)'] //使用foreach进行遍历,两个数组同时遍历,ther_id=id时将回帖数,赋予到port.php传递过来的值上
}
})
})
// console.log(da);
da.sort((a, b) => {
return (b['count(ther_id)']) - (a['count(ther_id)']);
}); //使用sort进行排序根据回帖数量排序
da.forEach(d => {
var title = d['title']
var time = d['time']
var content = d['content']
var id = d['id']
var area = d['area']
//根据键获取值
var con = `<tr>
<td class="col1">
<i class="sheng"></i>
<a href="./vies.php?id=${id}">${title}</a>
</td>
<td>${time}</td>
</tr>`
$('#out').append(con);
})
})
}
新帖区域,和其它区域共享port后端,获取数据,进行展示,根据时间进行排序
<?php
session_start();
if (@$_SESSION['isLogin'] != 1) {
die("未登入");
}
// 对登录进行判断
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>论坛</title>
<style type="text/css">
/*对网页进行第二次修饰*/
body {
font-size: 12px;
}
/*对整个标签,和表格 设置宽度为990像素*/
#discuss,
#discuss-datas {
width: 990px;
margin: auto;
}
#discuss div.mt {
/*高度,边框,背景*/
height: 30px;
border: 1px solid #DDDDDD;
border-top: 2px solid #999999;
background: #f7f7f7;
}
#discuss-content {
border-bottom: 1px solid #DDDDDD;
}
#discuss-datas tr.header td {
/*加粗 上下内边距 下边框*/
font-weight: bold;
padding: 5px 0;
border-bottom: 1px solid #DDDDDD;
color: #666666;
}
#discuss-datas td {
/*内容水平居中对齐*/
text-align: center;
}
#discuss-datas td.col1 {
/*宽度,文本左对齐*/
width: 620px;
text-align: left;
}
#discuss-datas tbody td {
/*文本颜色*/
color: #9c9c9c;
}
#discuss a {
/*改链接颜色 去掉下划线*/
text-decoration: none;
color: #005aa0;
}
#discuss a:hover {
text-decoration: underline;
}
#discuss-datas tbody td {
/*上下内边距 下边框*/
padding: 5px 0px;
border-bottom: 1px dotted #DDDDDD;
}
/*给论坛内容加标签 加图标*/
#discuss i {
/*左内边距 下内边距高度 背景图*/
padding-left: 21px;
padding-bottom: 5px;
background: url(img/c63802c9ee7e4ddec0e53e152e665ea.png) no-repeat;
background-size: 100%;
}
#discuss div.mt a {
float: left;
width: 100px;
height: 30px;
text-align: center;
line-height: 30px;
}
#discuss div.mt a:hover {
text-decoration: none;
color: #E4393C;
}
#discuss div.mt a.current {
border: 1px solid #DDDDDD;
border-top: 2px solid #E4393C;
border-bottom: 0;
background: #ffffff;
margin-top: -6px;
height: 35px;
line-height: 35px;
color: #E4393C;
}
#search {
float: right;
}
#show {
color: blue;
}
#block {
width: 400px;
margin: 0 auto;
background-color: #f4f4f4;
padding: 20px;
display: none;
}
#block label {
font-size: 18px;
color: #333;
}
#block input[type="text"],
#block textarea {
width: 100%;
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block select {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block input[type="button"] {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
</style>
<script src="../base/jquery-3.4.1.min.js"></script>
</head>
<body onload="port()">
<!--论坛div-->
<div id="discuss">
<!--页签菜单栏-->
<div class="mt">
<a href="home hot.php">热度贴</a>
<a href="home new.php" class="current">新发帖</a>
<a href="home dis.php">讨论区</a>
<a href="home wat.php">灌水区</a>
</div>
<!--讨论内容-->
<div id="discuss-content">
<!--表格内容-->
<table id="discuss-datas">
<!--标题栏-->
<tr class="header">
<td class="col1">主题</td>
<!-- <td>作者</td> -->
<td>时间</td>
</tr>
<!--内容栏-->
<tbody id="out">
</tbody>
</table>
<!--显示的拓展内容-->
<div id="discuss-total">
<div class="new_discuss" align="right">
有问题要与其他用户讨论
<div id="show" onclick="show()">[发表帖子]</div>
<div id="block">
<label for="">标题:</label>
<input type="text" id="title"><br>
<textarea name="" id="word" cols="30" rows="10"></textarea>
<select name="" id="sele">
<option value="dis">讨论区</option>
<option value="wat">灌水区</option>
</select>
<input type="button" value="发表" onclick="pub()">
</div>
</div>
</div>
</div>
</div>
</body>
<script>
</script>
</html>
新帖区域JS
function show() {
if (document.getElementById("block").style.display == "none") {
document.getElementById("block").style.display = "block";
} //判断原本属性的是否为隐藏状态,进行转换
else {
document.getElementById("block").style.display = "none";
}
}
function pub() {
var title = $('#title').val();
var word = $('#word').val();
var sele = $('#sele').val();
// alert(title+word+sele);
if (title == "") {
alert('标题不能为空')
} else {
if (word == "") {
alert('内容不能为空')
} else {
var data = "title=" + title + "&word=" + word + "&sele=" + sele;
$.post(
'pub.php',
data,
function(data) {
alert(data);
location.href = 'home new.php';
}
)
}
}
}
function port() {
$.get('port.php', (data) => {
// alert(data);
var da = eval(data);
// alert(da);
da.sort((a, b) => {
return new Date(b.time) - new Date(a.time);
}); //使用sort进行排序,根据时间进行排序
da.forEach(d => {
var title = d['title']
var time = d['time']
var content = d['content']
var id = d['id']
var area = d['area']
//根据键获取值
var con = `<tr>
<td class="col1">
<i class="sheng"></i>
<a href="./vies.php?id=${id}">${title}</a>
</td>
<td>${time}</td>
</tr>`
$('#out').append(con);
})
})
}
灌水区前端,和其它区域共享port后端,获取数据,进行展示
<?php
session_start();
if(@$_SESSION['isLogin']!=1){
die ("未登入");
}
// 对登录进行判断
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>论坛</title>
<style type="text/css">
/*对网页进行第二次修饰*/
body{font-size: 12px;
}
/*对整个标签,和表格 设置宽度为990像素*/
#discuss,#discuss-datas{
width: 990px;
margin: auto;
}
#discuss div.mt{
/*高度,边框,背景*/
height: 30px;
border: 1px solid #DDDDDD;
border-top: 2px solid #999999;
background: #f7f7f7;
}
#discuss-content{
border-bottom: 1px solid #DDDDDD;
}
#discuss-datas tr.header td{
/*加粗 上下内边距 下边框*/
font-weight: bold;
padding: 5px 0;
border-bottom: 1px solid #DDDDDD;
color: #666666;
}
#discuss-datas td{
/*内容水平居中对齐*/
text-align: center;
}
#discuss-datas td.col1{
/*宽度,文本左对齐*/
width: 620px;
text-align: left;
}
#discuss-datas tbody td{
/*文本颜色*/
color: #9c9c9c;
}
#discuss a{
/*改链接颜色 去掉下划线*/
text-decoration: none;
color: #005aa0;
}
#discuss a:hover{
text-decoration: underline;
}
#discuss-datas tbody td{
/*上下内边距 下边框*/
padding: 5px 0px;
border-bottom: 1px dotted #DDDDDD;
}
/*给论坛内容加标签 加图标*/
#discuss i{
/*左内边距 下内边距高度 背景图*/
padding-left: 21px;
padding-bottom: 5px;
background:url(img/c63802c9ee7e4ddec0e53e152e665ea.png) no-repeat;
background-size: 100%;
}
#discuss div.mt a{
float:left;
width: 100px;
height: 30px;
text-align: center;
line-height: 30px;
}
#discuss div.mt a:hover{
text-decoration: none;
color: #E4393C;
}
#discuss div.mt a.current{
border: 1px solid #DDDDDD;
border-top: 2px solid #E4393C;
border-bottom: 0;
background: #ffffff;
margin-top: -6px;
height: 35px;
line-height: 35px;
color: #E4393C;
}
#search{
float: right;
}
#show{
color: blue;
}
#block {
width: 400px;
margin: 0 auto;
background-color: #f4f4f4;
padding: 20px;
display: none;
}
#block label {
font-size: 18px;
color: #333;
}
#block input[type="text"], #block textarea {
width: 100%;
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block select {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
#block input[type="button"] {
font-size: 16px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
</style>
<script src="../base/jquery-3.4.1.min.js"></script>
</head>
<body onload="port()">
<!--论坛div-->
<div id="discuss">
<!--页签菜单栏-->
<div class="mt">
<a href="home hot.php">热度贴</a>
<a href="home new.php">新发帖</a>
<a href="home dis.php">讨论区</a>
<a href="home wat.php" class="current">灌水区</a>
</div>
<!--讨论内容-->
<div id="discuss-content">
<!--表格内容-->
<table id="discuss-datas">
<!--标题栏-->
<tr class="header">
<td class="col1">主题</td>
<!-- <td>作者</td> -->
<td>时间</td>
</tr>
<!--内容栏-->
<tbody id="out">
</tbody>
</table>
<!--显示的拓展内容-->
<div id="discuss-total">
<div class="new_discuss" align="right">
有问题要与其他用户讨论
<div id="show" onclick="show()">[发表帖子]</div>
<div id="block">
<label for="">标题:</label>
<input type="text" id="title"><br>
<textarea name="" id="word" cols="30" rows="10"></textarea>
<select name="" id="sele">
<option value="dis">讨论区</option>
<option value="wat">灌水区</option>
</select>
<input type="button" value="发表" onclick="pub()">
</div>
</div>
</div>
</div>
</div>
</body>
<script>
</script>
</html>
灌水区JS
function show(){
if (document.getElementById("block").style.display=="none") {
document.getElementById("block").style.display="block";
} //判断原本属性的是否为隐藏状态,进行转换
else{
document.getElementById("block").style.display="none";
}
}
function pub(){
var title=$('#title').val();
var word=$('#word').val();
var sele=$('#sele').val();
// alert(title+word+sele);
if (title=="") {
alert('标题不能为空')
}else{
if (word=="") {
alert('内容不能为空')
}else{
var data="title="+title+"&word="+word+"&sele="+sele;
$.post(
'pub.php',
data,
function(data){
alert(data);
location.href='home wat.php';
}
)
}
}
}
function port(){
$.get('port.php',(data)=>{
// alert(data);
var da=eval(data);
// alert(da);
da.forEach(d => {if(d.area=='wat'){
var title=d['title']
var time=d['time']
var content=d['content']
var id=d['id']
var area=d['area']
//根据键获取值
var con=`<tr>
<td class="col1">
<i class="sheng"></i>
<a href="./vies.php?id=${id}">${title}</a>
</td>
<td>${time}</td>
</tr>`
$('#out').append(con);
}
})
})
}
最终效果