tp5框架查询怎么在条件处加括号()?
在那navcat 里写好了sql,不知道怎么用tp5写进代码里,在tp5框架中的代码是
model('MaterialLike')->alias('like_material')
->join('materials materials' , $materialsAlias.'id = '.$likeMaterailsAlias. 'material_id')
->where($map)
->where(function ($query) use ($where_map){
$query->where($where_map);
})->whereOr(function ($query) use ($where_or_map){
$query->where($where_or_map);
})
->field($field)
->order($order)
->page($page,$limit)
->select();
然后得到的sql是这样的
SELECT
`materials`.`id`,
`materials`.`uid`,
`materials`.`title`,
`materials`.`type`,
`materials`.`tag`,
`materials`.`description`,
`materials`.`content`,
`materials`.`photo_list`,
`materials`.`video_list`,
`materials`.`view`,
`materials`.`likes`,
`materials`.`share`,
`materials`.`comment`,
`materials`.`customer`,
`materials`.`create_time`,
`materials`.`is_top`,
`materials`.`status`
FROM
`ap_material_like` `like_material`
INNER JOIN `ap_materials` `materials` ON `materials`.`id` = `like_material`.`material_id`
WHERE
`materials`.`seller_id` = 2
AND `materials`.`status` = 1
AND `materials`.`display` = 1
AND
(
`materials`.`m_category_id` IN ( 10001, 10005, 10008 )
AND ( ( `materials`.`tag` LIKE '%胖%' ) OR ( `materials`.`content` LIKE '%胖%' ) )
AND `like_material`.`uid` = '196893'
AND `like_material`.`typeid` = 3
AND `like_material`.`status` = 1
)
OR (
`materials`.`m_category_id` IN ( 10011, 10012, 10013, 10014, 10015 )
AND ( ( `materials`.`title` LIKE '%胖%' ) OR ( `materials`.`description` LIKE '%胖%' ) OR ( `materials`.`tag` LIKE '%胖%' ) )
AND `like_material`.`uid` = '196893'
AND `like_material`.`typeid` = 3
AND `like_material`.`status` = 1
)
ORDER BY
`like_material`.`create_time` DESC
LIMIT 0,
20
我想在代码里再加个括号,如下,该怎么加呢?
SELECT
`materials`.`id`,
`materials`.`uid`,
`materials`.`title`,
`materials`.`type`,
`materials`.`tag`,
`materials`.`description`,
`materials`.`content`,
`materials`.`photo_list`,
`materials`.`video_list`,
`materials`.`view`,
`materials`.`likes`,
`materials`.`share`,
`materials`.`comment`,
`materials`.`customer`,
`materials`.`create_time`,
`materials`.`is_top`,
`materials`.`status`
FROM
`ap_material_like` `like_material`
INNER JOIN `ap_materials` `materials` ON `materials`.`id` = `like_material`.`material_id`
WHERE
`materials`.`seller_id` = 2
AND `materials`.`status` = 1
AND `materials`.`display` = 1
AND ( {括号开头}
(
`materials`.`m_category_id` IN ( 10001, 10016, 10017 )
AND ( ( `materials`.`tag` LIKE '%胖%' ) OR ( `materials`.`content` LIKE '%胖%' ) )
AND `like_material`.`uid` = '196893'
AND `like_material`.`typeid` = 3
AND `like_material`.`status` = 1
)
OR (
`materials`.`m_category_id` IN ( 10020, 10021, 10022, 10023, 10024 )
AND ( ( `materials`.`title` LIKE '%胖%' ) OR ( `materials`.`description` LIKE '%胖%' ) OR ( `materials`.`tag` LIKE '%胖%' ) )
AND `like_material`.`uid` = '196893'
AND `like_material`.`typeid` = 3
AND `like_material`.`status` = 1
)
){括号结束}
ORDER BY
`like_material`.`create_time` DESC
LIMIT 0,
20
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
andWhere方法
普通的用
$where[] = ['isputaway', '=', 0];
带括号的用
最后直接where($where)就行