首页 > Web开发 > 详细

ThinkPHP的多表查询+分页范例

时间:2015-10-27 20:22:42      阅读:218      评论:0      收藏:0      [点我收藏+]

ThinkPHP的多表查询+分页范例
对于一个PHP程序员来说,多表查询是经常遇到的事,下面介绍一下ThinkPHP的多表查询+分页范例

<?php

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

$page_size = 15; //每页显示记录数

$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();

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

$show = $Page -> show();
$this -> assign( "page", $show); //输出分页

?>

ThinkPHP的多表查询+分页范例

原文:http://my.oschina.net/136796827/blog/522777

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!