博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ecshop 后台分页功能
阅读量:5923 次
发布时间:2019-06-19

本文共 6228 字,大约阅读时间需要 20 分钟。

Ecshop分页规则,分以下几个步骤

1.点击类别,获取第一页获取默认分类列表数据

2.点击“下一页”,采用ajax调取分页内容

 

实例分析(比如订单列表分页admin/order.php)

1.先写一个function order_list() 模块,里面要包括可以进行排序,分页,查询等功能

2.在order.php里面写一个elseif ($_REQUEST['act'] == 'list') ,这里是显示默认分页数据

3.在order.php写一个query(listtable.js默认的是先读取$_REQUEST['act'] == 'query')排序、分页、查询都在query里面完成

4.html页面(默认order_list.html完整代码)

 

实战 ”微仓功能“

1.我先写一个function depot_log_list,可以进行排序、分类、查询。这个function里面很有讲究的

重点代码

function depot_list(){   //*f.获取上一次保存的查询条件(如果上一次有进行查询过,则直接从f开始)   $result = get_filter();    if ($result === false) {    // a.查询条件    $filter['goods_id'] = empty($_REQUEST['goods_id']) ? '' : trim($_REQUEST['goods_id']);        //b.记录总条数        $filter['record_count'] = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('depot_log') . $ex_where);        //c.分页大小        $filter = page_and_size($filter);    //d.查询的sql        $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('depot_log') . $ex_where .                " order by createtime desc LIMIT " . $filter['start'] . ',' . $filter['page_size'];    //e.保存查询条件(cookie保存)        set_filter($filter, $sql);    }    else    {   //*f.获取上一次保存的查询条件(如果没有进行查询过,则从a查询。)    sql=" role="presentation" style="position: relative;">sql=sql=sql = result['sql'];            filter=" role="presentation" style="position: relative;">filter=filter=filter = result['filter'];    }    $depot_list = $GLOBALS['db']->getAll($sql);  //g.组合成系统默认查询条件    $arr = array('depot_list' => $depot_list, 'filter' => $filter,        'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);    return $arr;}

e.f这两步骤非常的重要,还有if($result===false){}也非常重要

实例代码

function depot_list(){    $result = get_filter();        if ($result === false)    {        $filter['user_id'] = empty($_REQUEST['user_id']) ? '' : trim($_REQUEST['user_id']);        $filter['goods_stock'] = empty($_REQUEST['goods_stock']) ? '' : intval($_REQUEST['goods_stock']);                $filter['sort_by']    = empty($_REQUEST['sort_by'])    ? 'goods_stock' : trim($_REQUEST['sort_by']);  // js的listTable.sort排序功能,也可以user_id        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC'     : trim($_REQUEST['sort_order']);                $ex_where = ' WHERE 1 ';        $ex_where .=" AND user_id = '$filter[user_id]' ";                        $filter['record_count'] = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('depot') . $ex_where);        /* 分页大小 */        $filter = page_and_size($filter);        $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('depot') . $ex_where .                 " ORDER by " . $filter['sort_by'] . ' ' . $filter['sort_order'] .                " LIMIT " . $filter['start'] . ',' . $filter['page_size'];       // $filter['keywords'] = stripslashes($filter['keywords']);        set_filter($filter, $sql);    }    else    {        $sql    = $result['sql'];        $filter = $result['filter'];    }    $depot_list = $GLOBALS['db']->getAll($sql);    foreach($depot_list as $k=>$v){        $sql = "SELECT goods_name,goods_thumb from ".$GLOBALS['ecs']->table('goods')." where goods_id = ".$v['goods_id'];        $re = $GLOBALS['db']->getRow($sql);        $depot_list[$k]['name'] = $re['goods_name'];        $depot_list[$k]['goods_thumb'] = $re['goods_thumb'];                }    $arr = array('depot_list' => $depot_list, 'filter' => $filter,        'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);    return $arr;}

2.写一个列表

实例代码

elseif($_REQUEST['act'] == 'depot_log'){    $smarty->assign('ur_here',      '个人微仓操作记录');       $depot = depot_log_list();        //print_r($depot);    $smarty->assign('depot_log',    $depot['depot_list']);    $smarty->assign('filter',       $depot['filter']);    $smarty->assign('record_count', $depot['record_count']);    $smarty->assign('page_count',   $depot['page_count']);    $smarty->assign('full_page',    1);    assign_query_info();    $smarty->display('depot_log_list.htm');    }

3.写一个列表查询(这里的depot_log_query ,还可以承接html页面的<a href="javascript:listTable.sort('goods_stock', 'DESC'); ">)

/*会员微仓 ajax 翻页调用*/elseif ($_REQUEST['act'] == 'depot_list_query'){        $depot = depot_list();    //$depot = user_list();    $smarty->assign('depot',    $depot['depot_list']);    $smarty->assign('filter',       $depot['filter']);    $smarty->assign('record_count', $depot['record_count']);    $smarty->assign('page_count',   $depot['page_count']);        $sort_flag  = sort_flag($depot['filter']);    $smarty->assign($sort_flag['tag'], $sort_flag['img']);    make_json_result($smarty->fetch('depot_list.htm'), '', array('filter' => $depot['filter'], 'page_count' => $depot['page_count']));  // 注意此处的结构,缺少mke_json_result不行     }

4.html页面html代码

{
foreach from=$depot item=vo}
{foreachelse}
{
/foreach}
{
$lang.record_id}{
$sort_user_id}
缩略图 商品名称 库存 {
$lang.handler}
{
$vo.id}
{ $vo.goods_name} {
$vo.goods_stock}
{
$lang.no_records}
{
include file="page.htm"}

js代码

{
if $full_page}
{
/literal}{
include file="pagefooter.htm"}{
/if}

如果改变了,默认的query查询;则a,b两处都不可以少

 

分页实例化结构代码

Array(    [depot_list] => Array        (            [0] => Array                (                    [id] => 1                    [user_id] => 1                    [goods_id] => 2                    [goods_stock] => 2                    [goods_name] => 荷兰Nutrilon牛栏奶粉                 )            [1] => Array                (                    [id] => 7                    [user_id] => 1                    [goods_id] => 6                    [goods_stock] => 4                    [goods_name] => 1111                )        )    [filter] => Array        (            [user_id] => 1            [record_count] => 2            [page_size] => 4            [page] => 1            [page_count] => 1            [start] => 0        )    [page_count] => 1    [record_count] => 2)

 

 

 

 

转: https://www.cnblogs.com/wesky/p/5424685.html

你可能感兴趣的文章
《聚散两依依》
查看>>
小tips:你不知道的 npm init
查看>>
Mac笔记本中是用Idea开发工具在Java项目中调用python脚本遇到的环境变量问题解决...
查看>>
Jmeter也能IP欺骗!
查看>>
Rust 阴阳谜题,及纯基于代码的分析与化简
查看>>
ASP.NET Core的身份认证框架IdentityServer4(4)- 支持的规范
查看>>
(原創) array可以使用reference方式傳進function嗎? (C/C++)
查看>>
170多个Ionic Framework学习资源(转载)
查看>>
Azure:不能把同一个certificate同时用于Azure Management和RDP
查看>>
Directx11教程(15) D3D11管线(4)
查看>>
Microsoft Excel软件打开文件出现文件的格式与文件扩展名指定格式不一致?
查看>>
ios ble 参考
查看>>
linux中注册系统服务—service命令的原理通俗
查看>>
基于托管C++的增删改查及异步回调小程序
查看>>
Oracle DBMS_STATS 包 和 Analyze 命令的区别
查看>>
linux下基本命令
查看>>
windows server 2008R2 上安装配置freesshd
查看>>
手动删除SVCH0ST.EXE的方法
查看>>
已释放的栈内存
查看>>
Android网络之数据解析----SAX方式解析XML数据
查看>>