<!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>
<link rel="stylesheet" href="./message-check.css">
<link rel="stylesheet" href="./iconfont/iconfont.css">
<link rel="stylesheet" href="./box.css">
</head>
<body>
<?php
require 'connect.php';
if (isset($_GET['find_name'])) {
$sql = "select count(*) as count from usermessage join messageboard on usermessage.mb_id=messageboard.mb_id where mb_name like '%" . $_GET['find_name'] . "%'";
$res = mysqli_query($con, $sql);
if (!$res) {
echo "<script>alert('查询出错11!'); window.location.href='messageShow.php';</script>";
}
if (!mysqli_affected_rows($con)) {
echo "<script>alert('没有查询到数据!'); window.location.href='messageShow.php';</script>";
exit();
}
//$count = mysqli_num_rows($res);
while ($row = mysqli_fetch_array($res)) {
$count = $row['count'];
}
$sum = $count;
$size = 2;
$page = (isset($_GET['page'])) ? $_GET['page'] : 1;
$pagecount = ceil($sum / $size);
$sql1 = "select distinct mb_name from usermessage join messageboard on usermessage.mb_id=messageboard.mb_id where mb_name like '%" . $_GET['find_name'] . "%'";
$res1 = mysqli_query($con, $sql1);
} else {
$sql1 = "select * from messageboard";
$res1 = mysqli_query($con, $sql1);
// $sql1 = "select count(*) as count from messageboard";
// $res1 = mysqli_query($con, $sql1);
// $row1 = mysqli_fetch_array($res1);
// $count = $row1['count'];
$sql = "select count(*) as count from usermessage";
//$sql1 = "select * from messageboard";
$res = mysqli_query($con, $sql);
while ($row1 = mysqli_fetch_array($res)) {
$count = $row1['count'];
//echo $count;
}
//$count = count($row1);
// $count=mysqli_num_rows($res1);
$sum = $count;
$size = 2;
$page = (isset($_GET['page'])) ? $_GET['page'] : 1;
$pagecount = ceil($sum / $size);
}
?>
<!-- 留言搜索 -->
<div class="message-check">
<div class="message-container">
<ul class="messageCheck-ul">
<form action="messageShow.php" method="get" enctype="multipart/form-data">
<li class="messageCheck-find">
<span>留言搜素:</span>
<span class="messageCheckFind-input">
<input type="text" name="find_name" value="<?php echo $_GET['find_name'] ?>">
</span>
<input class="find" type="submit" value="搜索">
</li>
</form>
<li class="messageCheck-label">
<span>留言标签:</span>
<?php
while ($row = mysqli_fetch_array($res1)) {
?>
<span><?php echo $row['mb_name']; ?></span>
<?php
}
?>
</li>
<?php
if (isset($_GET['find_name'])) {
$sql = "select * from usermessage join messageboard on usermessage.mb_id=messageboard.mb_id where mb_name like '%" . $_GET['find_name'] . "%' order by um_id asc limit " . ($page - 1) * $size . "," . $size . ";";
$res = mysqli_query($con, $sql);
if ($res === false) {
echo "语法错误" . mysqli_error($con);
}
if (!mysqli_affected_rows($con)) {
echo "<script>alert('没有找到该信息!'); window.location.href='messageShow.php';</script>";
exit();
}
} else {
$sql = "select * from usermessage order by um_id asc limit " . ($page - 1) * $size . "," . $size . ";";
$res = mysqli_query($con, $sql);
}
while ($row = mysqli_fetch_array($res)) {
?>
<li class="messageCheck-result">
<span id="result-1">留言者:</span>
<span><?php echo $row['um_name']; ?></span>
<span id="result-2">留言时间:</span>
<span><?php echo $row['create_time']; ?></span>
<br><br>
<span id="result-3">留言内容:</span>
<span><?php echo $row['um_content']; ?></span>
<span id="result-4"><i>
<?php
echo "|<a href='message_update.php?um_id=" . $row['um_id'] . "'>编辑</a>|";
?></i>
<i> <?php
echo "|<a href='message_delete_do.php?um_id=" . $row['um_id'] . "'>删除</a>|";
?></i></span>
</li>
<?php
}
?>
<li class="pageCount">
<span>当前第<?php echo $page; ?>页,共有<?php echo $pagecount; ?>页</span>
</li>
<li class="page">
<?php
for ($i = 1; $i <= $pagecount; $i++) {
$find_name = $_GET['find_name'];
?>
<span><?php echo "|<a href='messageShow.php?page=$i&find_name=$find_name'>$i</a>|"; ?> </span>
<?php
}
mysqli_close($con);
?>
</li>
<li class="bott">
<ul>
<li><a href='?page=1& find_name=<?php echo $_GET['find_name'] ?>'>首页</a></li>
<li><a href='?page=<?php echo ($page > 1) ? ($page - 1) : 1; ?> & find_name=<?php echo $_GET['find_name'] ?>'>上一页</a></li>
<li><a href='?page=<?php echo ($page < $pagecount) ? ($page + 1) : ($pagecount); ?>& find_name=<?php echo $_GET['find_name'] ?>'>下一页</a></li>
<li><a href='?page=<?php echo $pagecount; ?>& find_name=<?php echo $_GET['find_name'] ?>'>尾页</a></li>
<li><a href='commitMessage.php'>插入</a></li>
</ul>
</li>
</ul>
</div>
</div>
<!-- /留言搜索 -->
</body>
</html>