/*********翻页**********/
#page-table a{padding: 5px;border: 1px solid #F00;margin: 5px;}
#page-table span.current{padding: 5px;background: #F00;margin: 5px;color:#fff;font-weight: bold;}
// 商品列表页
public function lst()
{
$model=D('goods');
//返回数据和翻页
$data=$model->search();
$this->assign($data);
$this->display();
}
//实现翻页,搜索和排序
public function search($perPage=1)
{
/********翻页*******/
//取出总的记录数
$count=$this->count();
//生成翻页类的对象
$pageObj=new \Think\Page($count,$perPage);
//设置样式
$pageObj->setConfig('next','下一页');
$pageObj->setConfig('prev','上一页');
//生成页面下面显示的上一页和下一页
$pageString=$pageObj->show();
/********取某一页的数据*******/
$data=$this->limit($pageObj->firstRow.','.$pageObj->listRows)->select();
/*********返回数据******/
return array(
'data'=>$data, //数据
'page' =>$pageString, //翻页数据
);
}
<!-- 商品列表 -->
<form method="post" action="" name="listForm" οnsubmit="">
<div class="list-div" id="listDiv">
<table cellpadding="3" cellspacing="1">
<tr>
<th>编号</th>
<th>商品名称</th>
<th>logo</th>
<th>市场价格</th>
<th>本店价格</th>
<th>上架</th>
<th>添加时间</th>
<th>操作</th>
</tr>
<?php foreach ($data as $k => $v): ?>
<tr class="tron">
<td align="center"><?php echo $v['id']; ?></td>
<td align="center" class="first-cell"><span><?php echo $v['goods_name']; ?></span></td>
<td align="center"> <img src="__PUBLIC__/Uploads/<?php echo $v['sm_logo']; ?>" /></td>
<td align="center"><?php echo $v['market_price']; ?></td>
<td align="center"><?php echo $v['shop_price']; ?></td>
<td align="center"><?php echo $v['is_on_sale']; ?></td>
<td align="center"><?php echo $v['addtime']; ?></td>
<td align="center">
<a href="<?php echo U('edit?id='.$v['id']); ?>">修改</a>
<a οnclick="return confirm('确定要删除吗?');" href="<?php echo U('delete?id='.$v['id']); ?>">删除</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<!-- 分页开始 -->
<table id="page-table" cellspacing="0">
<tr>
<td width="80%"> </td>
<td align="center" nowrap="true">
<?php echo $page; ?>
</td>
</tr>
</table>
<!-- 分页结束 -->
</div>
</form>