以主表article查询,起别名a,,联合表art_category,起别名c,条件是id等同,用join
field查询需要的字段,
where条件查询
order排序差
分页3个一页
// 多表联合查询
$data = Db::name(‘article’)
->alias(‘a’)
->join(‘art_category c’,‘a.category_id = c.category_id’)
->field(‘a.art_id,a.imageurl,a.title,a.art_desc,a.category_pid,a.create_time,c.category_id,c.category_name’)
->where(‘a.status’,1)
->order(‘a.art_id’,‘desc’)
->paginate(3);
//多表联合查询-内连接
a
r
t
i
c
l
e
L
i
s
t
=
D
b
:
:
n
a
m
e
(
"
t
p
a
r
t
r
e
l
a
c
a
t
e
g
o
r
y
"
)
−
>
a
l
i
a
s
(
"
a
r
c
"
)
−
>
j
o
i
n
(
′
t
p
a
r
t
i
c
l
e
a
′
,
′
a
.
a
r
t
i
d
=
a
r
c
.
a
r
t
i
d
′
,
′
i
n
n
e
r
′
)
−
>
w
h
e
r
e
(
′
a
r
c
.
c
a
t
e
g
o
r
y
i
d
′
,
articleList = Db::name("tp_art_rela_category") ->alias("arc") ->join('tp_article a','a.art_id = arc.art_id','inner') ->where('arc.category_id',
articleList=Db::name("tpartrelacategory")−>alias("arc")−>join(′tparticlea′,′a.artid=arc.artid′,′inner′)−>where(′arc.categoryid′,category_id)
->select();
2.
$page = $data->render();
//输出数据
t
h
i
s
−
>
a
s
s
i
g
n
(
′
d
a
t
a
′
,
this -> assign('data',
this−>assign(′data′,data);
//输出分页
t
h
i
s
−
>
a
s
s
i
g
n
(
′
p
a
g
e
′
,
this -> assign('page',
this−>assign(′page′,page);
return $this->fetch();
3.数据输出
{$vo.category_pid}/ {switch name='$vo.category_pid'} {case value='1'}vv{/case} {case value='4'}44{/case} {default /}其他 {/switch} -id:{$vo.category_id}
{$vo.create_time|date="Y-m-d",###}
321
4.html显示分页
{$page}
作者:milli236
来源:CSDN
原文:https://blog.csdn.net/milli236/article/details/86380931
版权声明:本文为博主原创文章,转载请附上博文链接!