thinkphp3.1 多表联合查询代码
php代码
public function info(){ $where['openid']=session('openid');////用户session $db = M("pay");//主表名 $table ="pay"; $table2 = "tupian";//联合查询表名 $page_size = 5; //每页显示记录数 import('ORG.Util.Page');// 导入分页类 $count = count( $db -> field('id') -> where($where) -> select() );//记录总数 $Page = new Page($count, $page_size, 5);// 实例化分页类 传入总记录数 $show = $Page->show();// 分页显示输出 $list = $db -> field( "$table.yin,$table.time,$table.status,$table2.cover_url,$table2.title,$table2.id" ) -> join( "$table2 on $table.pid=$table2.id" ) -> where( $where ) -> order( "$table.id desc" ) -> limit($Page->firstRow.",".$Page->listRows) -> select(); $this->assign('list',$list);// 赋值数据集 $this->assign('page',$show);// 赋值分页输出 $this->display(info); // 输出模板 }
html代码
<foreach name='list' item='v'> <div class="car-list"> <div class="car-item"> <a class="pro-img" href="{:U("article/index")}?id={$v.id}"><img class="lazyload" src="{$v.cover_url}" alt="{$v.title}" style="width:100px; " /></a> <a class="pro-name" href="{:U("article/index")}?id={$v.id}">{$v.title}</a> <a class="pro-name2" href="#">{$v.time|date="Y-m-d H:i:s",###}</a> <div class="price"> 消费 <span>{$v.yin}</span>银果 </div> </div> </foreach> <div class="pagination"> {$page} </div>