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;}
  • 相关阅读:
    Mysql存储类型选择
    Mysql的MVCC
    SQL标准中的四种隔离级别
    web权限管理总结
    关于oauth2中为什么不直接返回token而是传授权码code
    课程作业——爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离
    网络爬虫基础练习
    Python中文词频统计
    关于Maven的配置与学习
    课程作业——综合练习:英文词频统计
  • 原文地址:https://www.cnblogs.com/xm666/p/13888566.html
Copyright © 2011-2022 走看看