ThinkPHP的多表查詢+分頁範例

ThinkPHP的多表查詢+分頁範例
對於一個PHP程序員來講,多表查詢是常常遇到的事,下面介紹一下ThinkPHP的多表查詢+分頁範例 php

<?php 程序員

$db = M( "Article" );
$fix = C( "DB_PREFIX" );
$table = $fix."article";
$table2 = $fix."article_category"; this

$page_size = 15; //每頁顯示記錄數 ip

$record_sum = count( $db -> field('art_id') -> where( "art_public='1'" ) -> select() );//記錄總數
$Page = new ZYPage($record_sum, $page_size, 5);
$list = $db -> field( "$table.art_id,$table.art_title,$table.art_content,$table.art_description,$table2.cate_id,$table2.cate_name" ) ->
        join( "$table2 on $table.cate_id=$table2.cate_id" ) ->
        where( "$table.art_public='1'" ) ->
        order( "$table.art_create_time desc,$table.art_id desc" ) ->
        limit($Page->firstRow.",".$Page->listRows) ->
        select(); it

$this -> assign( "article", $list); //輸出文章列表 io

$show = $Page -> show();
$this -> assign( "page", $show); //輸出分頁 table

?> select

相關文章
相關標籤/搜索