mysarty实现分页(三)之显示数据

好了,前两篇文章已经写了两个类了,现在我们要调用这两个类,然后显示出我们的数据库里的数据

先是我的配置smarty的文件:

init.inc.php

<?php
    require './libs/Smarty.class.php';
    require './page.class.php';
    require './mydb.php';
    $tpl = new Smarty();
    $tpl->template_dir ='./templates';
    $tpl->compile_dir ='./templates_c';
    $tpl->left_delimiter = '<{';
    $tpl->right_delimiter = '}>';

?>

然后是我的调用类的文件

index.php

<?php
    include 'init.inc.php';
    if(isset($_GET['page'])){
        $page=$_GET['page'];
    }else{
        $page=1;
    }
    if($page==0){$page=1;}
    $mydb = new Mydb('shop_car','car');
    $count=$mydb->getcount();
    $fpage = new page($count,$page,5);
    $pageinfo = $fpage->getpageinfo();
    $products = $mydb->getcontent($pageinfo['pagesize'],$pageinfo['offset']);
    if($products){
        $tpl->assign('title','商品列表');
        $tpl->assign('url','index.php');
        $tpl->assign('list',$products);
        $tpl->assign('pageinfo',$pageinfo);
    }else{
        echo "数据读取失败";
        exit;
    }
    $tpl->display('login.html');
?>

还有我的html页面

login.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><{$title}></title>
</head>
<body>
<table border="1" align="center" width="500">
    <tr>
        <th colspan="4"><{$title}></th>
    </tr>
    <tr>
        <td>ID</td><td>商品名</td><td>所属类别</td><td>单价</td>
    </tr>
    <{section name=list loop=$list}>
        <tr>
            <td><{$list[list].id}></td><td>
            <{$list[list].car_name}></td>
            <td><{$list[list].car_type}></td>
            <td><{$list[list].unit_price}>元</td>
        </tr>
    <{/section}>
</table>
<br></br>
<br></br>
<div align="right">
<{if $pageinfo.prev}>
<a href="<{$url}>?page=<{$pageinfo.prev}>">上页</a>
<{/if}>
当前第<{$pageinfo.page}>页
<{if $pageinfo.next}>
<a href="<{$url}>?page=<{$pageinfo.next}>">下页</a>
<{/if}>
共<{$pageinfo.pagenum}>页,<{$pageinfo.count}>个商品
</div>
</body>
</html>

好了,这样再加上我先前的两个类,这样一个smarty的分页功能就实现了!!!
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值