ThinkPHP框架模型连贯操作(8)

WBOY
Release: 2016-06-13 12:11:25
Original
807 people have browsed it

ThinkPHP框架模型连贯操作(八)

Thinkphp的连贯操作使用起来也是很灵活:

*可能这里有的mysql函数没全部罗列出来,大家可以举一反三,形式雷同

一、常用连贯操作

1.where
帮助我们设置查询条件
2.order
对结果进行排序
$arr=$m->order('id desc')->select();
$arr=$m->order(array('id'=>'desc','sex'=>'asc'))->select(); 多个字段排序

//数组形式查询排序
$data['id']=array(2,3,4,'or'); //查id=2 or id=3 or id=4
$arr = $user->where($data)->order('id desc')->select();
3.limit
限制结果
limit(2,5)  //从2条开始取3条

limit('2,5')
limit(10)//limit(0,10)
//提供的方法没有前后顺序之分,但是最后一定要select
$arr=$m->order(array('id'=>'desc','sex'=>'asc'))->limit(10)->select(); 
4.field
设置查询字段
field('username as name,id')   //别名 
  或
field(array('username'=>'name','id')
field('id',true) //获取除了id以外的所有字段
$arr=$m->order('id'=>'desc')->limit(10)—>field('username as name,id')->select(); 
5.table
6.group
7.having
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template