2016-09-14 90 views
1

我在php中做了一個分頁的網頁。但我想包括一些過濾器來搜索這個分頁。所以如果有人有好的建議,會很好的收到。在PDO中過濾php/mysql

這裏是我做分頁的文件。名稱是,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> 
+1

WHERE CONCAT('id') - 爲什麼CONCAT當你有一列?你從「用戶」表中獲取「id」列,然後調用變量「articles」...你在輸入標籤中輸入「1」作爲你的「id」的值,它必須以字母開始......你必須描述你的問題更好,在我看來,你正試圖將分頁和搜索結合在同一頁面上,但我從你的問題中不能理解它。 – ban17

+0

是的,你是對的,我做的分頁非常好。但我無法將搜索與我的分頁結合起來。這僅僅是我的問題罷了。我有點迷路,爲此我解釋了一些我做過的步驟。我不說他們是否成功。我不是專業開發人員,所以我只是新手。 –

+0

抱歉,如果帖子不清楚我改變了。 –

回答

-1

我不知道,如果我知道你的意思「但我不能用我的分頁組合搜索。」但據我所知,你想在你的查詢中添加某種'where'語句。

這裏是這樣做的例子,我覺得從這個網站最後的代碼是你想要什麼:http://www.webreference.com/programming/php/search/2.html