tp中一个字段符合多个条件的查询,where like or

时间:2022-04-21 02:55:09

需求:要求查询news表中title 中包含 bh 或者nk 的资讯

1)sql语句为

        select id,title,keyword, from news where title like "%bh%" or titlelike "%nk%" ORDER BY add_time DESC limit 8

2)tp框架写法为

$where['title'] = array(['like', "%bh%"],['like',"%nk%",'or');
$data=M('news')
->field('id,title,keyword')
->where($where)
->order('add_time DESC')
->select();