pagination doesnt link to where clause when new page clicked(单击新页面时,分页不会链接到 where 子句)
本文介绍了单击新页面时,分页不会链接到 where 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 where 子句,显示所有类别,其中 id = 上一页的输入值.分页工作给了我正确的页数,where 子句给了我正确的记录.
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
指向每个页面的链接不标识 whereclause
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">
";
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;?>
推荐答案
将类别添加到链接:
$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;?>
这篇关于单击新页面时,分页不会链接到 where 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:单击新页面时,分页不会链接到 where 子句
基础教程推荐
猜你喜欢
- 使用 PDO 转义列名 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01