我用php做了一个网页分页。但我想包括一些过滤器搜索在这个分页。因此,如果有人有好的建议,会很好地接受。
这是我做分页的文件。名称是Index.php:
<?php
require_once 'database.php';
$database_connection = database_connect();
$title='hola';
$content='';
//user input
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$perPage = 2;
//Positioning
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
$art = $database_connection->query("SELECT id FROM coffee");
//Query
$articles = $database_connection->prepare("SELECT id FROM coffee LIMIT $start,$perPage");
$articles->execute();
$articles = $articles->fetchAll();
$resultado = $database_connection->query("SELECT COUNT(*) AS total FROM coffee");
$fila = $resultado->fetch(PDO::FETCH_ASSOC);
$total = $fila["total"];
$pages = ceil($total/$perPage);
include 'Template_1.php';
?>
这是我的html网站。模板:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css" />
</head>
<body>
<div id="wrapper">
<div id="banner">
</div>
<nav id="navigation">
<ul id="nav">
<li><a href="index.php">Home</a></li>
<li><a href="tool.php">Coffee</a></li>
<li><a href="manager.php">Shop</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<div id="content_area">
<?php
require_once("tool.php");
foreach ($articles as $article):
echo $article['id'];?>
</br><?php
endforeach;?></br><?php
for($x=1;$x<=$pages;$x++):?>
<a href="tool.php?page=<?php echo $x;?>"><?php echo $x;?></a>
<?php endfor;?>
</br>
<?php echo $content; ?>
</div>
<div id="sidebar">
</div>
<footer>
<p>All rights reserved</p>
</footer>
</div>
</body>
</html>
我不确定我是否知道你所说的"但是我不能将搜索与分页结合起来"是什么意思。但据我所知,你想在你的查询中添加某种'where'语句。
这里有这样做的例子,我认为这个网站的最后一个代码是你想要的:http://www.webreference.com/programming/php/search/2.html