php - 图像分页 - 如何在一个查询中获取所有参数
问题描述
我有一个分页系统,用于查看数据库中的图像。
所以每次我点击一个next / prev
按钮时,我都需要三个变量
问题 - 有没有办法让它们在一个查询中而不是为每个查询使用单独的查询?
$lm = 100; // limit per page
$off = 0; // offset - click on next prev buttons
$dim = '960 x 540'; // img dimensions
function get_images($lm, $off, $dim){
global $db;
//firstly I need total number of images
$st = $db->query("select count(*) as cnt from images");
$total = $st->fetchColumn();
//then I need number of 960 x 540 images
$st = $db->query("select * from images where dim = '" . $dim . "'");
$insel = $st->rowCount();
//then I need number of viewed images on a pagination system
$st = $db->query("select * from images where dim = '" . $dim . "' order by date desc limit " . $lm . "
offset " . $off);
$inview = $st->rowCount();
解决方案
$st = $db->query("select * from images where dim = '" . $dim . "' count(id) over(partition by id) as cnt count(dim) over(partition by dim) as insel order by date desc limit " . $lm . " offset " . $off);
但请确保您使用的 MySQL 版本大于或等于 8.0
推荐阅读
- java - 如何将 {key1=value1, key2=value2} 之类的字符串转换为 json 字符串或 Jsonobject?
- reactjs - ReactJS:以 pdf 格式渲染数学方程的 svg
- android - 无法使用自定义构建的系统映像启动 Android 模拟器
- php - 如何区分 phalcon 框架控制器中的多个按钮动作?例子; 提交、更新和清除按钮
- sql-server - 是否可以在 SQL Server Express 版本中配置 kerberos 身份验证?
- json - JSON 响应打印
- visual-studio-code - 如何在 VSCode 中访问片段扩展的用户设置
- python - 如何根据另外两个给定的图像对图像进行分类
- python - selenium.common.exceptions.InvalidArgumentException:消息:无效参数:使用 Selenium 调用 send_keys() 时找不到文件错误
- microsoft-graph-api - microsoft graph BETA 使用 isfavoritebydefault 添加 Microsoft Teams 频道