zoukankan      html  css  js  c++  java
  • thinkcmfx 查询可添加任意条件

    // function sp_sql_posts_paged_bykeyword($keyword,$tag,$pagesize=20,$pagetpl='{first}{prev}{liststart}{list}{listend}{next}{last}'){
    //     return ApiService::postsPagedByKeyword($keyword,$tag,$pagesize,$pagetpl);
    // }
    上面是原来的代码,
    下面是自定义方法 直接替换
    function sp_sql_posts_paged_bykeyword($keyword,$tag,$pagesize=20,$pagetpl='{first}{prev}{liststart}{list}{listend}{next}{last}'){ $where=array(); $tag=sp_param_lable($tag); $field = !empty($tag['field']) ? $tag['field'] : '*'; $limit = !empty($tag['limit']) ? $tag['limit'] : ''; $order = !empty($tag['order']) ? $tag['order'] : 'post_date'; //格式化关键词 $array_key = explode(" ",'%'.str_ireplace(" ","% %",trim($keyword," ")).'%'); // 生成查询条件 $map['post_keywords'] = array('LIKE', $array_key,'AND'); $map['post_title'] = array('LIKE', $array_key,'AND'); $map['post_content'] = array('LIKE', $array_key,'AND'); $map['_logic'] = 'OR'; // 封装查询条件 $where['_complex'] = $map; // 只查询已发布的内容 $where['status'] = array('eq',1); $where['post_status'] = array('eq',1); $where['search_true'] = array('eq',1); if (isset($tag['cid'])) { $where['term_id'] = array('in',$tag['cid']); } if (isset($tag['ids'])) { $where['object_id'] = array('in',$tag['ids']); } $join = "".C('DB_PREFIX').'posts as b on a.object_id =b.id'; $join2= "".C('DB_PREFIX').'users as c on b.post_author = c.id'; $rs= M("TermRelationships"); $totalsize=$rs->alias("a")->join($join)->join($join2)->field($field)->where($where)->count(); import('Page'); if ($pagesize == 0) { $pagesize = 20; } $PageParam = C("VAR_PAGE"); $page = new Page($totalsize,$pagesize); $page->setLinkWraper("li"); $page->__set("PageParam", $PageParam); $page->SetPager('default', $pagetpl, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => "")); $posts=$rs->alias("a")->join($join)->join($join2)->field($field)->where($where)->order($order)->limit($page->firstRow . ',' . $page->listRows)->select(); $content['count']=$totalsize; $content['posts']=$posts; $content['page']=$page->show('default'); return $content;}
  • 相关阅读:
    C# List<T>中Select List Distinct()去重复
    Spring.Net 简单入门学习
    [ASP.NET MVC]:
    打车题
    Vue------发布订阅模式实现
    Vue----数据响应原理
    小程序自定义导航栏_navigationStyle
    CleanWebpackPlugin最新版本使用问题
    js-事件函数调用简化
    用XHR简单封装一个axios
  • 原文地址:https://www.cnblogs.com/xm666/p/13888566.html
Copyright © 2011-2022 走看看