码迷,mamicode.com
首页 > 数据库 > 详细

php sql 多表查询 分页

时间:2015-12-07 22:28:22      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

 1 public function get_search($page=1){
 2    $slide=$_POST[‘slide‘];
 3    $page=trim($page);
 4    $arr=$this->M->get_all("SELECT a.* FROM `lx_z_news` as a where   a.`title` like ‘%".$slide."%‘ union all SELECT b.* from `lx_z_product` as b where  b.`title` like ‘%".$slide."%‘ ");
 5    $row=count($arr);
 6    $page2=Page($page,$row,10);
 7    $select_from=$page2[‘select_from‘];
 8    $select_limit=$page2[‘select_limit‘];
 9    $arr1=$this->M->get_all("SELECT ‘a‘ tbname,a.title,a.summary,a.id,a.c_time,a.status as thumb FROM `lx_z_news` as a where   a.`title` like ‘%".$slide."%‘ union all SELECT ‘b‘ tbname,b.title,b.summary,b.id,b.c_time,b.thumb from `lx_z_product` as b where  b.`title` like ‘%".$slide."%‘  limit $select_from,$select_limit ");
10     
11    foreach($arr1 as $key=>&$e){
12  
13       $e[‘title‘]=str_replace($slide, ‘<i style="color:red">‘.$slide.‘</i>‘, $e[‘title‘]);
14    }
15    unset($e);
16  
17    $this->assign("slide",$slide);
18    $this->assign(‘search_list‘,$arr1);
19    $this->assign(‘pagenav‘,$page2[‘pagenav‘]);
20    $this->assign(‘num‘,$row);
21    $this->display("search01.html");
22 }

0:多表  union all 不去重 、、、、union 去重  

1:‘a‘ tbname ,‘b‘ tbname  查出是哪个表的   

2:查询结果列字段必须相同

php sql 多表查询 分页

标签:

原文地址:http://www.cnblogs.com/simayubo/p/5027348.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!