2016-05-03 21 views
-1

我有一個where子句,顯示所有的分類,其中id =來自previouse頁面的輸入值。分頁工作給了我適量的頁面,where子句給了我正確的記錄。分頁沒有鏈接到where子句點擊新的頁面時

當我點擊頁面nuber然而,頁面上顯示的記錄是不是下一組所需的記錄,但所有記錄

鏈接到每一頁犯規identfy的whereclause

<?php 
include ('dbconnect.php'); 
$db = dbConnect(); // function defined in dbconnect.php 

echo $filmCategory = isset($_REQUEST['filmCategory']) ? $_REQUEST['filmCategory'] : null; 

$whereclause = "where c.category_id = '$filmCategory'"; 


require_once('functions.php'); 

//user input this will limit the amount of records per page the user can see 
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; 
$perPage = isset($_GET['per-page']) && $_GET['per-page'] <=15 ? (int)$_GET['per_page'] : 10; 

//positioning: replace certain variables within the query 
//this will be where the rows start from the calculation will work out if page is greater than 1 
//if the page is less than one it should be 0 
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0; 
//query to fetch required records 
$filmSQL = $db->prepare("SELECT SQL_CALC_FOUND_ROWS f.title, f.description, f.release_year, c.name, 
f.rating, f.last_update 
from nfc_film f 
inner join nfc_film_category fc 
on f.film_id = fc.film_id 
inner join nfc_category c 
on fc.category_id = c.category_id 
$whereclause 
LIMIT {$start}, {$perPage}"); 

// execute the query and get the title, description, release year, name, rating and last update of film 
$filmSQL->execute(); 

//echo the table with the titles and correct data from SQL 
echo "<table border=\"1\">\n"; 
    echo "<tr><th>Title</th><th>Description</th><th>Release Year</th><th>Category</th><th>Rating</th><th>Last Update</th></tr>"; 

    while ($filmInfo = $filmSQL->fetchObject()) { 

    $upperLower= upperFirst(lowercase($filmInfo->title)); 
    $uLDescription= firstUpper(lowercase($filmInfo->description)); 
    $noChar = substr($uLDescription,0,100).'...'; 
    echo "<form action='filmInfo.php' method='get'>"; 
     echo "<tr> 
      <td><input type='text' name='filmInfo' value='{$upperLower}'</td> 
      <td><p>$noChar.</p></td> 
      <td>{$filmInfo->release_year}</td> 
      <td>{$filmInfo->name}</td> 
      <td>{$filmInfo->rating}</td> 
      <td>{$filmInfo->last_update}</td> 
      <td><input type='submit' value='Film Details' </td> 
     </tr>"; 
     echo" </form>"; 

    } 
echo "</table>"; 
//pages 
$total = $db->query("SELECT FOUND_ROWS() as total")->fetch()['total']; 
$pages = ceil($total/$perPage); 


?> 

<div id="pagintation"> 
    <?php for($x = 1; $x <= $pages; $x++): ?> 
     <a href="?page=<?php echo $x; ?>"><?php echo $x; ?></a> 
    <?php endfor;?> 

+0

旁註:如果您在使用這個''div id =「pagintation」>'的CSS確保你在這裏使用相同的單詞。 'pagintation'被拼寫錯誤。所以如果你的CSS讀作'#pagination',你的CSS將無法工作。這就是它如何拼寫順便說一句。 ;-) –

回答

0

類別添加到鏈接:

$cat = isset($_REQUEST['category']) ? "&category=" . $_REQUEST['category'] : ''; 
?> 

<div id="pagintation"> 
    <?php for($x = 1; $x <= $pages; $x++): ?> 
     <a href="?page=<?php echo $x . $cat; ?>"><?php echo $x; ?></a> 
    <?php endfor;?> 
+0

這個問題似乎是一個轉發http://stackoverflow.com/q/37003490/ –

+0

@ Fred-ii-這是一個不同的問題,當他點擊頁面鏈接時根本沒有顯示錶格。它是由頂部的if(isset($ _ POST ['search']))'引起的,他從這個版本中刪除了它。 – Barmar

+0

儘管如此,95%的代碼都是相同的。祝你好運與此;-) –