新年
快乐

垃圾堆中的精品

垃圾堆中的精品

ECSHOP 分页技术实现

PHP 页面获取数据函数:

        //分页技术
        $page = isset($_REQUEST[‘page’]) && intval($_REQUEST[‘page’])  ? intval($_REQUEST[‘page’]) : 1;
        $size = 15;
       
        /* 获取记录条数 */
        $sql = “SELECT COUNT(*) FROM ” . $GLOBALS[‘ecs’]->table(‘supplier_order’) .”AS o LEFT JOIN  ” . $GLOBALS[‘ecs’]->table(‘supplier’) . ” AS s ON o.supplier_id = s.supplier_id LEFT JOIN  ” . $GLOBALS[‘ecs’]->table(‘users’) . ” AS u ON u.user_id = o.user_id WHERE s.daili_id = ‘” . $user_id . “‘”;
        $record_count = $GLOBALS[‘db’]->getOne($sql);
       
        // 分页函数
        $pager = get_pager(‘user.php’, array(‘act’ => $GLOBALS[‘action’]), $record_count, $page, $size);
        $GLOBALS[‘smarty’]->assign(‘pager’, $pager);
       
        // 获取记录
        $sql = “SELECT * FROM ” . $GLOBALS[‘ecs’]->table(‘supplier_order’) .”AS o LEFT JOIN  ” . $GLOBALS[‘ecs’]->table(‘supplier’) . ” AS s ON o.supplier_id = s.supplier_id LEFT JOIN  ” . $GLOBALS[‘ecs’]->table(‘users’) . ” AS u ON u.user_id = o.user_id WHERE s.daili_id = ‘” . $user_id . “‘”;
        $res = $GLOBALS[‘db’]->selectLimit($sql, $pager[‘size’], $pager[‘start’]);
       
        /* 取出数据 */
        while ($row = $GLOBALS[‘db’]->fetchRow($res)){
            $row[‘add_time’] = date(‘Y-m-d H:i:s’, $row[‘add_time’]);
            $arr[] = $row;
        }
       
        return $arr;

模板页添加分页lbi:

<!– #BeginLibraryItem “/library/pages.lbi” –><!– #EndLibraryItem –>

 

保存刷新,PerFect!

评论回复

回到顶部