pagination doesnt link to where clause when new page clicked

核能气质少年 提交于 2019-12-04 06:50:00

问题


i have a where clause that shows all categorys where the id=the input value from the previouse page. the pagination works giving me the right amount of pages and the where clause gives me the correct records.

when i click on a page nuber however the records shown on the page are not the next set of required records but all records

the link to to each page doesnt identfy the 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;?>


回答1:


Add the category to the links:

$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;?>


来源:https://stackoverflow.com/questions/37007149/pagination-doesnt-link-to-where-clause-when-new-page-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!