筛选重复+翻页问题
程序员文章站
2022-04-18 14:31:45
...
我的表里货号有重复的,首先要筛选掉重复的记录第个货号显示一条。
然后分页。
现在问题是筛选做完了,但我做的是先分页,再筛选,结果每页显示的不一样多,
设置80条,有的筛选掉30条,就只能显示50条了。
怎么才能先筛选再分页?
//以下是分页数量函数
function _divide_page($_sql,$_size){
global $_page,$_pagesize,$_pagenum,$_pageabsolute,$_num;
//分页模块
if (isset($_GET['page'])) {$_page = $_GET['page'];
if (empty($_page) || $_page else {$_page = intval($_page);}}
else {$_page = 1;}
$_pagesize = $_size;
//首页要得到所有的数据总和
$_num = mysql_num_rows(mysql_query($_sql));
if ($_num == 0) {$_pageabsolute = 1;}
else {$_pageabsolute = ceil($_num / $_pagesize);}
if ($_page > $_pageabsolute) {$_page = $_pageabsolute;}
$_pagenum = ($_page - 1) * $_pagesize;
$_pageabsolute = ceil($_num / $_pagesize);
}
//以下是分页标签函数
function _partition_page(){
global $_page,$_pageabsolute,$_num;
echo '
}
//以下是页面头部
global $_pagenum,$_pagesize;
_divide_page(
"SELECT * FROM product ",80
);
$result = mysql_query("SELECT * FROM product ORDER BY id DESC LIMIT $_pagenum,$_pagesize");
//下面是HTML
while (!!$_n = mysql_fetch_array($result)) {
if ($_n['num'] != $_o && !empty($_n['img'])) {
?>
然后分页。
现在问题是筛选做完了,但我做的是先分页,再筛选,结果每页显示的不一样多,
设置80条,有的筛选掉30条,就只能显示50条了。
怎么才能先筛选再分页?
//以下是分页数量函数
function _divide_page($_sql,$_size){
global $_page,$_pagesize,$_pagenum,$_pageabsolute,$_num;
//分页模块
if (isset($_GET['page'])) {$_page = $_GET['page'];
if (empty($_page) || $_page else {$_page = intval($_page);}}
else {$_page = 1;}
$_pagesize = $_size;
//首页要得到所有的数据总和
$_num = mysql_num_rows(mysql_query($_sql));
if ($_num == 0) {$_pageabsolute = 1;}
else {$_pageabsolute = ceil($_num / $_pagesize);}
if ($_page > $_pageabsolute) {$_page = $_pageabsolute;}
$_pagenum = ($_page - 1) * $_pagesize;
$_pageabsolute = ceil($_num / $_pagesize);
}
//以下是分页标签函数
function _partition_page(){
global $_page,$_pageabsolute,$_num;
echo '
- ';
- 共有'.$_num.'个会员 ';
- |';
echo ' - ';
} else {
echo ' - | ';
- ';
- >> ';
- >| ';
- >> ';
- >| ';
- '.$_page.'/'.$_pageabsolute.'页 ';
// echo '
if ($_page == 1) {
echo '
echo '
}
if ($_page == $_pageabsolute) {
echo '
echo '
} else {
echo '
echo '
}
echo '
echo '
}
//以下是页面头部
global $_pagenum,$_pagesize;
_divide_page(
"SELECT * FROM product ",80
);
$result = mysql_query("SELECT * FROM product ORDER BY id DESC LIMIT $_pagenum,$_pagesize");
//下面是HTML
while (!!$_n = mysql_fetch_array($result)) {
if ($_n['num'] != $_o && !empty($_n['img'])) {
?>
-
// $_receive = mysql_query("SELECT * FROM img WHERE code='{$_n['img']}' ");
// $_m = mysql_fetch_array($_receive)
?>
id=
回复讨论(解决方案)
调用时 _divide_page(
"SELECT * FROM product ",80
);
你的sql指令怎么没有筛选条件?
上一篇: PHP大量Session的散列及过期回收