Make a filter in php / mysql

0

For those who are not clear topic I share the index and the template of my page. What it does to me is paging. I want to add a filter to filter this page simply. 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';
?>

Template:

<!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>

I thought that in the other way it would be better but good I ask you to see if someone gives me support or advises me enough to carry out my goal a thousand thanks.

    
asked by Perl 14.09.2016 в 14:50
source

1 answer

1

To make a request

answered by 14.09.2016 в 16:45