欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

为什么每页显示数量不一样

程序员文章站 2024-02-12 18:38:46
...
本来每页显示数设为10条,但是加上红色部分代码,就会乱掉,有的页显示2条记录,有的页显示3条记录,有的页显示4条记录。。。。。。没有红色部分代码就正常

。。。。。。省略
$sql = "SELECT ck.chuku_id,ck.status,ck.danhao,ck.type,ck.sq_time,ck.bl_time,sq_user.real_name as sq_realname,bl_user.real_name as bl_realname FROM " .
$fdyu->table('oa_chuku') . " as ck left join " .
$fdyu->table('oa_chuku_huopin') . " as ck_hp on ck.chuku_id=ck_hp.chuku_id left join " .
$fdyu->table('oa_huopin') . " as hp on ck_hp.huopin_id=hp.huopin_id left join " .
$fdyu->table('users') . " as sq_user on ck.chuku_user_id=sq_user.user_id left join " .
$fdyu->table('users') . " as bl_user on ck.jingban_user_id=bl_user.user_id" .
$sql_where . $sql_qx;
。。。。。。。省略


回复讨论(解决方案)

这样基本上看不出什么吧,把分页的罗辑也贴出来看看呢.

$sql_where = ' where ck.school_id=' . $school_id;

if($bl_time_start != '')
{
$sql_where .= " and ck.bl_time>=" . gmstr2time($bl_time_start);
}
if($bl_time_end != '')
{
$sql_where .= " and ck.bl_time }
if($danhao != '')
{
$sql_where .= " and ck.danhao like '%" . mysql_like_quote($danhao) . "%'";
}

if($type != 0)
{
$sql_where .= " and ck.type=" . $type;
}

if($banzhuren_id != 0)
{
$sql_where .= " and ck.chuku_user_id=" . $banzhuren_id;
}

if($name != '')
{
$sql_where .= " and hp.name like '%" . mysql_like_quote($name) . "%'";
}

//判断是否有权限,如果没有则用户只能查看自己的入库单
if (strpos($_SESSION['action_list'],'oa_churuku_list') === false && strpos($_SESSION['action_list'], 'all') === false){
$sql_qx=" and (ck.chuku_user_id=".$_SESSION['userid']." or ck.jingban_user_id=".$_SESSION['userid']." or ck.check_user_id=".$_SESSION['userid'].") order by ck.chuku_id desc";
}else{
$sql_qx=" order by ck.chuku_id desc";
}

$sql = "SELECT ck.chuku_id,ck.status,ck.danhao,ck.type,ck.sq_time,ck.bl_time,sq_user.real_name as sq_realname,bl_user.real_name as bl_realname FROM " .
$fdyu->table('oa_chuku') . " as ck left join " .
$fdyu->table('oa_chuku_huopin') . " as ck_hp on ck.chuku_id=ck_hp.chuku_id left join " .
$fdyu->table('oa_huopin') . " as hp on ck_hp.huopin_id=hp.huopin_id left join " .
$fdyu->table('users') . " as sq_user on ck.chuku_user_id=sq_user.user_id left join " .
$fdyu->table('users') . " as bl_user on ck.jingban_user_id=bl_user.user_id" .
$sql_where . $sql_qx;

$res = $db->selectLimit($sql, $size, ($page-1) * $size);
$arr = array();
if ($res)
{
while ($row = $db->fetchRow($res))
{
.......省略
}
}

$page = !empty($_REQUEST['p']) && intval($_REQUEST['p']) > 0 ? intval($_REQUEST['p']) : 1;
$size = 10;
$count = get_chuku_count($school_id,$bl_time_start,$bl_time_end,$danhao,$type,$banzhuren_id,$name);
$pages = ($count > 0) ? ceil($count / $size) : 1;
$smarty->assign('count', $count); //记录总数
$smarty->assign('pages', $pages); //总页数
$smarty->assign('chuku_list', get_chuku_list($school_id,$bl_time_start,$bl_time_end,$danhao,$type,$banzhuren_id,$name,$page,$size));
$smarty->assign('pagenavi', get_pagenavi($page,$pages,5));
其中,get_chuku_list()这个函数就是我发的那些代码