繁体   English   中英

图像分页 - 如何在一个查询中获取所有参数

[英]images pagination - how to get all params in one single query

我有一个用于查看数据库中图像的分页系统。
所以每次我点击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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM