Blogger Information
Blog 50
fans 0
comment 0
visits 31572
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp数据库管理
手机用户1580651468
Original
960 people have browsed it

thinkphp数据库管理

一、建好数据表

二、Thinkphp 排序、翻页、聚合查询

1、排序 order,order by

  1. $user = Db::name('adver')->order('sort desc,id desc')->select();

2、翻页、获取多少条 limit,如果就1个参数,代表获取多少条。

  1. $user = Db::name('shop')->limit(0,5)->select()->toArray();
  2. $user = Db::name('shop')->limit(5,5)->select()->toArray();

3、翻页,还有更简单的方法。 page,第一个参数是当前页数,第二参数获取多少条

  1. $user = Db::name('shop')->page(2,5)->select()->toArray();

4、以上我们学过的链式方法,都可以用一条代码展示出来。功能冲突的不能同时使用

  1. $user = Db::name('shop') ->field('id,title,img,old_price,price')
  2. ->where('id','>=',6)
  3. ->order('id desc')
  4. ->select()
  5. ->toArray();

5、聚合查询

  1. $user = Db::name('shop') ->field('id,title,img,old_price,price')
  2. ->where('id','>=',6)
  3. ->order('id desc')
  4. ->count();
  5. $user = Db::name('order')
  6. ->where('status','>=',2)
  7. ->sum('sj_price');
  8. print_r($user);
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments