TP的多表查询+分页范例
来源:互联网 发布:中国域名管理中心 编辑:程序博客网 时间:2024/05/22 11:37
<span style="font-size:14px;">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); //输出分页?></span>
例2:(自己写的)
//显示某一用户,某一订单详情(order详情、fllow_order详情 public function viewOneOrder(){ import('ORG.Util.Page'); $userid = $_POST['userid']; $orderid = $_POST['orderid']; if(empty($userid)){ $result=array('err_no' =>1001,'err_msg'=>"userid is empty"); //用户id为空 echo json_encode($result); exit; } if(empty($orderid)){ $result=array('err_no' =>1001,'err_msg'=>"orderid is empty"); //跟单id为空 echo json_encode($result); exit; } $db = M( "order" );$fix = C( "DB_PREFIX" );$table = $fix."order";$table2 = $fix."follow_order";$page_size = 1; //每页显示记录数//$count = count( $db -> field('art_id') -> where( "art_public='1'" ) -> select() );//记录总数//查询满足条件的总页数$data = $db -> field( "$table.id,$table.name,$table.remark as o_remark,$table2.time,$table2.remark as f_remark" ) -> join( "$table2 on $table.id=$table2.order_id" ) -> where( "$table.userid = '$userid' and $table.id = '$orderid' " ) -> order( "$table.id" ) -> select(); $count = count($data); $Page = new Page($count, 1); $data = $db -> field( "$table.id,$table.name,$table.remark as o_remark,$table2.time,$table2.remark as f_remark" ) -> join( "$table2 on $table.id=$table2.order_id" ) -> where( "$table.userid = '$userid' and $table.id = '$orderid' " ) -> order( "$table.id" ) -> limit($Page->firstRow.",".$Page->listRows) -> select(); if($data){ $result=array('err_no' =>1,'err_msg'=>"success",'data'=>$data,'TotalPages'=>$Page->getTotalPages(),'count'=>$count); //调用行业资讯列表成功,并返回总页数 (存在数据) echo json_encode($result); exit; }else{ $result=array('err_no' =>0,'err_msg'=>"order is empty"); //调用失败 (不存在数据) echo json_encode($result); exit; } //var_dump($order->getlastsql()); }
0 0
- TP的多表查询+分页范例
- tp多表查询
- tp多表查询
- 基于TP的数据库查询和分页类应用模块
- tp的复合查询
- tp框架中的多表查询操作
- tp关联表查询
- 一个完整的Ajax查询及对查询结果实现分页的范例
- JadePool应用范例:查询与分页
- 表关联查询范例
- 多表查询分页
- 多表查询的存储过程分页
- 通用SQL数据库查询语句范例(多表查询)
- 通用SQL数据库查询语句范例(多表查询)
- 通用SQL数据库查询语句范例(多表查询)
- 通用SQL数据库查询语句范例(多表查询)
- 一对多的分页查询
- 多表查询结果,分页
- SVM 支持向量机 opencv实现
- do while
- spark1.3.1使用基础教程
- spark原理介绍
- mysql快速入门
- TP的多表查询+分页范例
- 关于Nios中对EPCS进行flash烧写出现以下错误Error: Error code: 8 for command: nios2-flash-programmer...的解决办法
- 公钥,私钥和数字签名这样最好理解
- SSD 之BBM坏块管理机制
- HIVE快速入门
- hadoop的关键进程
- sqoop 1.4.4-cdh5.1.2快速入门
- 蓝牙相关技术概述
- android 状态栏及通知栏中的下载动画效果实现