laravel where中多条件查询
1、
http://www.mobanstore.com/doc/bianchengkaifa/119.html
//初学laravel 发现他的查询构造器很好用
//如下
$user = DB::table('users')->where('name', 'John')->first();
var_dump($user->name); //但是 如果where里面有多个查询条件怎么办呢? 我查了查源码 原来是可以用数组的,这样就灵活多了 public static function article_data($id)
{
//$id = Input::get('id');
$where = array('a.id' => $id, 'a.rm'=>0); // 关键是这里
$data = DB::table('article AS a')
//->where('a.id', '=', $id)
->where($where)
->leftJoin('category AS b', 'a.catid', '=', 'b.id')
->select('a.*', 'b.name AS catname', 'b.id AS catid' )
->get(); if($data)
{
return $data[0];
}
//$sql = DB::getQueryLog();
//var_export( $sql);die; }
2、
http://www.cnblogs.com/yjf512/p/4031782.html
//解决办法:在基类中扩展一个multiwhere
//于是我就在BaseModel中定义了: // 多where
public function scopeMultiwhere($query, $arr)
{
if (!is_array($arr)) {
return $query;
} foreach ($arr as $key => $value) {
$query = $query->where($key, $value);
}
return $query;
} //这样子,上面的语句就可以这么使用:
Student::multiwhere([‘female’=>1, ’teacher_id’ => 4, ‘class_id’ => 3])->get();
laravel where中多条件查询的更多相关文章
- C# 将Access中时间段条件查询的数据添加到ListView中
C# 将Access中时间段条件查询的数据添加到ListView中 一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Col ...
- Hibernate中的条件查询完成类
Hibernate中的条件查询有以下三个类完成: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类
- SSM-MyBatis-13:Mybatis中多条件查询
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 实体类 public class Book { private Integer bookID; private ...
- ormlite 在android中 排序 条件查询
ormlite 在android中 排序 条件查询 all = dao.queryBuilder().orderBy("Id", true).where().eq("Ty ...
- Hibernate中的条件查询完毕类
Hibernate中的条件查询有下面三个类完毕: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类
- ThinkPHP中 按条件查询后列表显示
最近在项目中遇到了需要根据下拉框的条件筛选出符合条件的数据,然后进行列表显示的问题. 在ThinkPHP中进行列表显示的传统过程:通过在后台控制器中查询出数据,然后通过$this->assign ...
- SQL中多条件查询括号的用途
界面: 代码 0 posted @ 2009-12-15 13:28 唔愛吃蘋果 阅读(8640) 评论(0) 编辑 收藏
- 【.Net】C# 将Access中时间段条件查询的数据添加到ListView中
一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Columns集合中添加表头中的文字. 二.利用代码给ListView添加 ...
- Mybatis-技术专区-中的条件查询createCriteria example里面的条件
之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用. 在我们前台查询的时候会有许多 ...
随机推荐
- [笔记]--Python字符串处理
一.截取字符串中的内容 1.截取: MsiExec.exe /I{AC76BA86-7AD7-2052-7B44-AB0000000001} 中的: {AC76BA86-7AD7-2052-7B44- ...
- Python性能优化的20条建议 (转载)
优化算法时间复杂度 算法的时间复杂度对程序的执行效率影响最大,在Python中可以通过选择合适的数据结构来优化时间复杂度,如list和set查找某一个元素的时间复杂度分别是O(n)和O(1).不同的场 ...
- poj 3580 SuperMemo
题目连接 http://poj.org/problem?id=3580 SuperMemo Description Your friend, Jackson is invited to a TV sh ...
- Tutorial: Importing and analyzing data from a Web Page using Power BI Desktop
In this tutorial, you will learn how to import a table of data from a Web page and create a report t ...
- azure 云服务证书下载方式
打开地址自动下载证书,vs中项目-右键-发布-导入证书. https://manage.windowsazure.cn/publishsettings/index 在 Visual Studio 中打 ...
- 论C# java的基本类型
http://blog.csdn.net/com360/article/details/8201930 http://www.360doc.com/content/13/0818/13/8074294 ...
- OC中的NSNumber、NSArray、NSString的常用方法
和C语言不同,在Objective-C语言中,有单独的字符串类NSString.C语言中,string是由 char(ASCLL码)字符组成 OC中,字符串是由unichar(Unicode)字符组成 ...
- FastDFS安装配置
FastDFS FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传.下载等服务 ...
- VBS基础篇 - 常用函数
Option Explicit '*********************************Date/Time函数******************************* 'CDate函 ...
- Android -- 倒计时的实现
CountDownTimer CountDownTimer这个 ...