ThinkPHP 根据请求参数进行组合查询

更新日期: 2019-10-17 阅读次数: 3562 字数: 60 分类: thinkphp

例如,默认是查询 status 为 1 的文章;

当请求参数中,包含分类 ID 时,查询条件再加上 category_id。

$where = array(
    'status' => 1,
);
if ($category_id != -1) {
    $where['category_id'] = $category_id;
}

$news = M("article")
    ->where($where)
    ->select();

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式