php - 如何使用 PHP PDO 在同一页面上发送可变数据?
问题描述
我正在为大约 1500 行的表格进行分页。
$numperpage = 50;
$countsql = $connect->prepare("select COUNT(id) from prana");
$countsql->execute();
$row = $countsql->fetch();
$numrecords = $row[0];
$numlinks = ceil($numrecords/$numperpage);
$page = $_GET['start'];
if (!$page) $page = 0;
$start = $page * $numperpage;
echo "start is ".$start.'<br>';
if(isset($_POST["action"]))
{
$query = "
SELECT * FROM prana WHERE product_status = '1' limit $start,$numperpage";
echo $output;
for ($i=0;$i<$numlinks;$i++)
{
$y = $i+1;
echo '<a href="index.php?start='.$i.'"> '.$y.' </a>';
}
从 <a href="index.php?start='.$i.'"> 我在我的 url 中获取 start 的值,但对于 $page = $_GET['start'] 它显示 Undefined array key start 。并且开始变量保持在0。
这是我的参考:- https://www.youtube.com/watch?v=TI78ax23qZg 请帮忙。
解决方案
要摆脱警告,请从以下位置更改您的代码:
$page = $_GET['start'];
if (!$page) $page = 0;
进入:
$page = isset($_REQUEST['start']) ? $_REQUEST['start'] + 0 : 0;
使用Where
$_REQUEST['start']
代替$_GET['start']
以确保逻辑有效,即使方法不是GET
。而“+ 0”是为了确保它是数字的。
此外,start
在单击其中一个链接之前不会设置参数。
推荐阅读
- ios - 返回 UITableViewCell 子类类型的通用函数
- python - 如何比较两个txt文件并删除python中第二个文件中的重复项
- python - Python Selenium for 在具有相同 ID 的多个输入字段上循环
- angular - Angular中的空显示
- visual-studio - 使用“创建测试证书”作为我的 excel 插件证书来源是不好的做法吗?
- docker - 如何更改 Nginx 配置中的根路径
- css - 旋转:abc ddeg;仅受 Firefox 支持,但添加浏览器前缀似乎也破坏了 Firefox
- next.js - nextjs:多个孩子被传递给了“x”的“href”,但只支持一个孩子
- python - 主循环运行太多次并在二十一点游戏中给出太多牌
- firebase - (RN) 可能未处理的 Promise Rejection (id: 0):推送通知