使用PDO在php/mysql中进行过滤

使用PDO在php/mysql中进行过滤,php,mysql,pdo,Php,Mysql,Pdo,我用php做了一个网页的分页。但我想在此分页中包含一些要搜索的过滤器。所以如果有人有好的建议,就会受到好的接待 这是我分页的文件。名称为Index.php: <?php require_once 'database.php'; $database_connection = database_connect(); $title='hola'; $content=''; //user input $page = isset($_GET['page']) ? (int)$_GET['page'

我用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”语句


这里有一些这样做的例子,我认为这个网站的最后一个代码就是你想要的:

WHERE CONCAT(
id
)-当你有一个专栏时为什么要CONCAT?从“users”表中获取“id”列并调用变量“articles”。。。您将“1”作为输入标记中“id”的值,它必须以字母开头。。。你必须更好地描述你的问题,在我看来,你试图在同一页上结合分页和搜索,但我没有从你的问题中理解。是的,你是对的,我分页做得很好。但我不能将搜索与分页结合起来。这是我的问题,仅此而已。我有点迷茫,为此,我解释了一些我为获得成功所做的步骤。我不说他们成功与否。我不是专业的开发人员,所以我只是个新手。如果帖子不清楚,我很抱歉,我改成ok。看看如何使用jQuery数据表。它们的集成非常简单,提供了这种开箱即用的功能,以及其他很酷的特性,如列排序等。