ThinkPHP中提到查询实例

ThinkPHP中关联查询(即多表联合查询)可以使用 table(),1、原生查询示例,test1 as a,a.title,在THINKPHP中关联查询(多表查询)可以使用 table(),1、table()

ThinkPHP中涉嫌查询(即多表联合查询)能够选取 table(State of Qatar方法或和join方法,具体接纳如下例所示:

1、原生查询示例:
代码如下:
金沙澳门官网7817网址,$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、join(卡塔尔(قطر‎方法身先士卒:
代码如下:
$user = new Model(‘user’);
$list = $user->join(‘RIGHT JOIN user_profile ON user_stats.id =
user_profile.typeid’ );
3、table(State of Qatar方法亲自过问:
代码如下:
$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();

本文实例陈说了ThinkPHP中关系查询的用法。分享给我们供咱们参照他事他说加以考察。具体深入分析如下:

1、原生查询示例:

在THINKPHP中涉及查询(多表查询卡塔尔(قطر‎能够应用 table(卡塔尔方法或和join方法,如下示例所示:

复制代码 代码如下:$Model = new Model(State of Qatar;
$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);

1、table() 复制代码 代码如下:$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();
2、join() 复制代码 代码如下:$user = new
Model(‘user’卡塔尔(قطر‎; 
$list = $user->join(‘RIGHT JOIN user_profile ON user_stats.id =
user_profile.typeid’ )->select();
3、原生查询 复制代码 代码如下:$Model = new
Model(State of Qatar; 
$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);
4、多表查询 复制代码
代码如下:$Model->田野(‘user.name,role.title’卡塔尔国->table(‘think_user
user,think_role role’)->limit(10)->select();
或:
复制代码
代码如下:$Model->田野(‘user.name,role.title’卡塔尔->table(array(‘think_user’=>’user’,’think_role’=>’role’))->limit(10)->select();