搜索参数传递
- 采用get方式,URL传递,主要考虑翻页page的传递;
- 出于安全需要,对参数进行过滤;
@$branch_id = get_param('branch_id'); if ($branch_id == "") { $branch_id = $_COOKIE["branch_id"]; } @$major_id = explode(',', get_param('major_name'))[0]; @$pool_able = $_GET['pool_able']; if ($pool_able == ""){ $pool_able='0'; } @$keys = get_param('keys');
翻页参数传递
- 获取page参数,并格式化为十进制,判断为0是,自动为1;
- 设置默认每页的数据数量变量$pagenum;
- 设置偏移量$startI
$page = get_param('page'); $page = intval($page) == 0 ? 1 : intval($page); $pagenum = 30; $startI = $page * $pagenum - $pagenum;
layui翻页格式传递
- 总记录的计算:
$count = count($row_c);
- 搜索条件必须和主语句同步,否则总记录不准确,会导致翻页错乱;
- code=0,msg=0,是layui的固定格式,不可缺少;
完整搜索和翻页代码
//获取总记录; $sql_c = "select a.pool_id,a.member_id,a.branch_id,a.major_id,a.pool_address,a.pool_mask,a.pool_gateway,a.pool_able,b.major_id,b.major_name from " . $db->table('pool') . " AS a," . $db->table('category') . " AS b WHERE 1"; $sql_c .= " AND a.major_id = b.major_id AND a.branch_id =" . $branch_id; if ($major_id != "") { $sql_c .= " AND a.major_id =" . $major_id; } if ($keys != "") { $sql_c .= " AND a.pool_address like '%" . $keys . "%'"; } if ($pool_able != "") { $sql_c .= " AND a.pool_able =" . $pool_able; } $sql_c .= " ORDER BY a.pool_id ASC"; $row_c = $db->queryall($sql); $count = count($row_c);
@$branch_id = get_param('branch_id'); if ($branch_id == "") { $branch_id = $_COOKIE["branch_id"]; } @$major_id = explode(',', get_param('major_name'))[0]; @$pool_able = $_GET['pool_able']; if ($pool_able == ""){ $pool_able='0'; } @$keys = get_param('keys'); $page = get_param('page'); $page = intval($page) == 0 ? 1 : intval($page); $pagenum = 30; $startI = $page * $pagenum - $pagenum; //获取总记录; $sql_c = "select a.pool_id,a.member_id,a.branch_id,a.major_id,a.pool_address,a.pool_mask,a.pool_gateway,a.pool_able,b.major_id,b.major_name from " . $db->table('pool') . " AS a," . $db->table('category') . " AS b WHERE 1"; $sql_c .= " AND a.major_id = b.major_id AND a.branch_id =" . $branch_id; if ($major_id != "") { $sql_c .= " AND a.major_id =" . $major_id; } if ($keys != "") { $sql_c .= " AND a.pool_address like '%" . $keys . "%'"; } if ($pool_able != "") { $sql_c .= " AND a.pool_able =" . $pool_able; } $sql_c .= " ORDER BY a.pool_id ASC"; $row_c = $db->queryall($sql); $count = count($row_c); $pages = getPages($count, $page, $pagenum); $sql = "select a.pool_id,a.member_id,a.branch_id,a.major_id,a.pool_address,a.pool_mask,a.pool_gateway,a.pool_able,b.major_id,b.major_name from " . $db->table('pool') . " AS a," . $db->table('category') . " AS b WHERE 1"; $sql .= " AND a.major_id = b.major_id AND a.branch_id =" . $branch_id; if ($major_id != "") { $sql .= " AND a.major_id =" . $major_id; } if ($keys != "") { $sql .= " AND a.pool_address like '%" . $keys . "%'"; } if ($pool_able != "") { $sql .= " AND a.pool_able =" . $pool_able; } $sql .= " ORDER BY a.pool_id ASC LIMIT " . $startI . ',' . $pagenumt; $row = $db->queryall($sql);
lockdatav Done!