thinkphp左连接查询,原生查询

时间:2016-08-04 11:51:16   收藏:0   阅读:2007
  1. 原生查询:

$Model = new Model();
$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;
$voList = $Model->query($sql);

  2.左查询

$model=M(‘picture‘);
            $lists=$model->alias(‘p‘)->join(‘LEFT JOIN cgw_terms t on p.parent_id=t.term_id‘)->join(‘LEFT JOIN cgw_users u on p.post_author=u.id‘)->field(‘p.*,t.name,u.user_login‘)->order(‘p.post_modified desc‘)->page($nowpage, $limits)->select();


本文出自 “高山” 博客,谢绝转载!

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!