php sql 多表查詢 分頁

來源:互聯網
上載者:User

標籤:

 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 多表查詢 分頁

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.