修改错误错误提示:1Warning mysqli_num_rows expects parameter 1 to be mysqli_result bool given in wwwwwwrootulq0c7fensharemodphp on line 172Warning mysqli_fetch_array expects parameter 1 to be mysqli_result boo
<?php include '../../config.php'; ?>
<?php
$search = isset($_GET['search']) ? $_GET['search'] : '';
$Page = isset($_GET['page']) ? $_GET['page'] : 1;
$PageSize = 20;
$startRow = ($Page - 1) * $PageSize;
$maxRecords = 100; // Set maximum number of records to display
$str = "SELECT * FROM mod WHERE (name LIKE '%" . $search . "%' OR shows LIKE '%" . $search . "%' OR banben LIKE '%" . $search . "%') LIMIT " . $startRow . "," . $PageSize;
mysqli_set_charset($con, 'utf8');
$result = mysqli_query($con, $str);
$arr = array();
// Calculate total number of rows
$totalRows = mysqli_num_rows(mysqli_query($con, "SELECT * FROM mod WHERE (name LIKE '%" . $search . "%' OR shows LIKE '%" . $search . "%' OR banben LIKE '%" . $search . "%')"));
$totalPages = ceil($totalRows / $PageSize);
// Set maximum number of records to display
if ($totalRows > $maxRecords) {
$totalRows = $maxRecords;
$totalPages = ceil($totalRows / $PageSize);
if ($Page > $totalPages) {
$Page = 1;
$startRow = 0;
}
$str = "SELECT * FROM mod WHERE (name LIKE '%" . $search . "%' OR shows LIKE '%" . $search . "%' OR banben LIKE '%" . $search . "%') LIMIT " . $startRow . "," . $PageSize;
$result = mysqli_query($con, $str);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>电脑mod下载</title>
<script src="/js/protect/1.0.0.js"></script>
<link rel="stylesheet" href="/css/button/1.0.0.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>
body {
font-family: Arial, sans-serif;
}
<pre><code> form {
text-align: center;
margin-bottom: 20px;
}
.search-container {
display: flex;
justify-content: center;
align-items: center;
}
.search-container input[type="text"] {
padding: 10px;
font-size: 20px;
border: 1px solid #ccc;
flex: 1;
}
.search-container button[type="submit"] {
padding: 10px 20px;
font-size: 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 3px;
margin-left: 10px;
}
select {
padding: 5px;
border: 1px solid #ccc;
}
h1 {
font-size: 30px;
text-align: center;
margin-top: 0;
}
.result a {
display: block;
margin-bottom: 10px;
text-decoration: none;
color: #000;
font-weight: bold;
}
.result a:hover {
color: #4CAF50;
}
.result p {
margin-bottom: 5px;
}
.result .analysis {
margin-top: 10px;
font-style: italic;
color: #666;
}
.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
}
.pagination a, .pagination span {
padding: 5px 10px;
margin: 0 2px;
background-color: #4CAF50;
color: white;
text-decoration: none;
}
</style>
</code></pre>
</head>
<body>
<h1>优质网站资源查询</h1>
<div>
<form action="" method="get">
<div class="search-container">
<input type="text" name="search" placeholder="资源好杂,遵简一下">
<button type="submit" name="submit">搜索</button>
</div>
</form>
<div class="result">
<?php while ($row = mysqli_fetch_array($result)) { ?>
<a style="font-size:20px;" href="<?php echo $row['web']; ?>" target="_blank"><?php echo $row['name']; ?></a>
<p><?php echo $row['shows']; ?></p>
<p class="analysis">版本:<?php echo $row['banben']; ?></p>
<hr>
<?php } ?>
</div>
<div class="pagination">
<?php
$query_string = $_SERVER['QUERY_STRING'];
$query_string = preg_replace("/&?page=\d+/", "", $query_string); // 移除现有的页码参数
if (strpos($query_string, 'search=') === false) {
$query_string .= '&search=' . urlencode($search); // 向查询字符串中添加搜索关键字参数
}
<p>if ($Page > 1) {
echo '<a href="?page=1&' . $query_string . '" class="pagination-link">首页</a>';
echo '<a href="?page=' . ($Page - 1) . '&' . $query_string . '" class="pagination-link">上一页</a>';
} else {
echo '<span class="pagination-link disabled">首页</span>';
echo '<span class="pagination-link disabled">上一页</span>';
}</p>
<p>for ($i = 1; $i <= $totalPages; $i++) {
if ($i == $Page) {
echo '<span class="pagination-link current">' . $i . '</span>';
} else {
echo '<a href="?page=' . $i . '&' . $query_string . '" class="pagination-link">' . $i . '</a>';
}
}</p>
<p>if ($Page < $totalPages) {
echo '<a href="?page=' . ($Page + 1) . '&' . $query_string . '" class="pagination-link">下一页</a>';
echo '<a href="?page=' . $totalPages . '&' . $query_string . '" class="pagination-link">末页</a>';
} else {
echo '<span class="pagination-link disabled">下一页</span>';
echo '<span class="pagination-link disabled">末页</span>';
}</p>
<pre><code> ?>
</div>
</div>
<a href="/" class="home-button">返回主页</a>
</code></pre>
</body>
</html
原文地址: https://www.cveoy.top/t/topic/h6Pr 著作权归作者所有。请勿转载和采集!