thinkphp兩表,多表聯合查詢及分頁的連貫操作寫法


  1. ThinkPHP中關聯查詢(即多表聯合查詢)可以使用 table() 方法或和join方法,具體使用如下例所示:
  2. 1、原生查詢示例:
  3. 代碼如下:
  4. $Model = new Model();
  5.  $sql = 'select a.id,a.title,b.content from think_test1 as a, think_test2 as b where a.id=b.id '.$map.' order by a.id '.$sort.' limit '.$p->firstRow.','.$p->listRows;
  6.  $voList = $Model->query($sql);
  7. 2join()方法示例:
  8. 代碼如下:
  9. $user = new Model('user');
  10.  $list = $user->join('RIGHT JOIN user_profile ON user_stats.id = user_profile.typeid' );
  11. 3table()方法示例:
  12. 代碼如下:
  13. $list = $user->table('user_status stats, user_profile profile')->where('stats.id = profile.typeid')->field('stats.id as id, stats.display as display, profile.title as title,profile.content as content')->order('stats.id desc' )->select();

 

 

$data=$manage->table('template, app')->where('template.appid = app.appid')->field('template.teptype, app.appname')->order('template.id asc')->limit($Page->firstRow.','.$Page->listRows)->select();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM