ThinkPHP多表联合查询以及自带分页类用法
//控制器下面的方法:
public function index_recommendlist(){
$m=D('index_car');
if ($_GET['p'] == '') {
$p = 1;
} else {
$p = $_GET['p'];
}
$pagecontent = 10;
$xuhao = $p * $pagecontent - ($pagecontent - 1);
$this->assign('xuhao', $xuhao);
import('ORG.Util.Page');// 导入分页类
$count = $m->order("sort desc")->count();// 查询满足要求的总记录数
$Page = new Page($count, $pagecontent);// 实例化分页类 传入总记录数和每页显示的记录数
$show = $Page->show();// 分页显示输出
$list=$m->join('left join car_cate on car_cate.cate_id = index_car.cate_id')->field('index_car.name as name,index_car.img as img,car_cate.name as cate_name,index_car.sort as sort,index_car.id as id,index_car.is_recommend as is_recommend')->order("index_car.sort desc")->limit($Page->firstRow . ',' . $Page->listRows)->select();
$this->assign('list',$list);
$this->assign('page', $show);// 赋值分页输出
$this->display();
}
//模板
<table width="100%"bgcolor="#ccc" cellpadding="10" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td>序号</td>
<td>汽车名称</td>
<td>图片</td>
<td>车型</td>
<td>是否推荐</td>
<td>排序</td>
<td>操作</td>
</tr>
<volist name='list' id='list' empty='请插入数据'>
<tr bgcolor="#FFFFFF">
<td>{$xuhao++}</td>
<td>{$list.name}</td>
<td><img src="__ROOT__/public/upload/tui/{$list.img}" width="100" height="50"></td>
<td>{$list.cate_name}</td>
<td>{$list['is_recommend']==1?"<font color=red>是</font>":"否"}</td>
<td><input name="sort" type="text" value="{$list.sort}" id="{$list.id}" style="width:30px;"></td>
<td><a href="{:U('Main/index_recommendupdata')}?id={$list.id}">修改</a> | <a href="{:U('Main/indextui_del')}?id={$list.id}" onclick="javascript:return confirm('确定要删除吗?')">删除</a></td>
</tr>
</volist>
</table>
版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。
本文链接:ThinkPHP多表联合查询以及自带分页类用法 - https://wlphp.com/?post=63