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

问题描述 投票:0回答:1

我有一个分页系统,用于查看数据库中的图像。因此,每次单击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();
php mysql
1个回答
0
投票

嗯,您可以用下划线分隔的字符串(例如, limit_offset_dim

$param = "10_20_15";
$limit = explode("_", $param)[0];
$offset = explode("_", $param)[1];
$dim = explode("_", $param)[2];
© www.soinside.com 2019 - 2024. All rights reserved.