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>
 
         

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM