php:
(1)Yundan代表我们建立的数据库模型,where是查询条件,其中user是数据库表里的字段,$username是查询的变量,如果是一个已知的字符可以改写为where('user=101'),后面的paginate表示查询后分页大小为每页5条内容。
(2)assign是变量赋值,查询到的内容赋给list,html页面就可以直接使用list来调用查询到的数据。
public function index()
{
$list = Yundan::where('user',$username)->paginate(5);//(1)
$this ->view ->assign('list',$list);//(2)
return $this ->view ->fetch('index');
}
Html页面:
volist标签是用于查询集的结果输出,name要设为php中赋值的变量list,id可以随意设置,但同时之后调用的时候也是通过此id进行调用。
{$list->render()}表示是分页码的显示,可能样式有些丑陋,需要加载bootstrap.css样式表或自定义修改其格式。
<table class="table table-responsive">
<thead>
<tr>
<th colspan="1">序号</th>
<th colspan="3">内容</th>
<th colspan="4">操作</th>
</tr>
</thead>
<tbody id="tbody-result">
{volist name='list' id='vo'}
<tr>
<td>{$vo.yundanid}</td>
<td>重量:{$vo.c1}</td>
<td>PH:{$vo.c2}</td>
<td>含水率:{$vo.c3}</td>
<td><a href=\"#\">撤回</a></td>
<td><a href=\"#\">修改</a></td>
<td><a href=\"#\">报错</a></td>
<td><a href=\"#\">未确认</a></td>
</tr>
{/volist}
</tbody>
</table>
<div style="text-align: center">{$list->render()}</div>
默认的分页效果,显示的顺序是根据数据库表中的数据的顺序,我们也可以自定义进行排序,进行如下更改即为降序排列
$list = Yundan::where('user',$username)->order(['id'=>'desc'])->paginate(5)
这里只是大概介绍方法,实际问题可能都要做些调整,有时候真的觉得可能很简单的东西,但是会搞很久.......沮丧