[英]images pagination - how to get all params in one single query
I have a pagination system for viewing images from database.我有一个用于查看数据库中图像的分页系统。
So each time I click on a next / prev
buttons I need three variables所以每次我点击
next / prev
上一个按钮时,我都需要三个变量
Question - is there a way to get them in one single query and not using a separate query for each of them?问题 - 有没有办法在一个查询中获取它们,而不是对每个查询使用单独的查询?
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.