ThinkPHP的多表查询+分页范例
2015-10-27 17:53
507 查看
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); //输出分页
?>
对于一个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); //输出分页
?>
相关文章推荐
- PHP POST获取的JSON使用json_decode返回NULL
- mac安装mcrypt PHP扩展
- Matplotlib以小时为单位统计文件数据
- Thinkphp——商品加入购物车在购物车列表显示(还有购物车删除)
- php开发日记之生成图片
- 详解PHP序列化反序列化的方法
- 工厂方法及其设计原则
- 使用 OpCache 提升 PHP 性能
- php使用ZipArchive函数实现文件的压缩与解压缩
- 使用PHP搭建自己的MVC框架
- 学习PHP到底要学习哪些东西?
- php过滤所有的空白字符(空格、全角空格、换行等)
- 005.Output 格式符
- webstorm与phpstorm主题配置
- PHP的APC模块实现上传进度条
- php yii .htaccess
- PHP将图片处理成圆角
- 将数据库转php json数组格式
- php做购物商品库存解决方法
- 第 四 十 二 天:FTP 的 相 关 问 题