• CI框架分页查询实现


    //进行数据分页
        /*
        @f_page 第一分页
        @s_page 第二分页
        @total_sql    总数sql
        @index_sql    列表sql
        @order        排序sql
        @select        查询sql
        */
        function get_page($f_page,$s_page="index",$total_sql,$index_sql,$order,$select='',$segment=4)
        {
            $this->CI = &get_instance();
            $page = $this->CI->uri->segment(4) ? : 1;
    
            $per_page =  10;
        
            $config['uri_segment'] = $segment; 
            $config['next_link'] = _('下一页');
            $config['prev_link'] = _('上一页');
            $config['first_link'] = _('首页');
            $config['last_link'] = _('尾页');
    
            if(!empty($select)){
            $offset = empty($this->CI->input->get('per_page')) == true ? 0 : $this->CI->input->get('per_page');
            $search_url =  preg_replace('/(&per_page=)(d*)/','', strstr($_SERVER["REQUEST_URI"], '?'));
            $config['base_url'] = '/management/'.$f_page.'/'.$s_page.'/'.$search_url;
            $config['page_query_string'] = true;
            }else
            {
                $offset = empty($this->CI->uri->segment(4)) == ture ? 0 :$this->CI->uri->segment(4);
                $config['base_url'] = '/management/'.$f_page.'/'.$s_page;
            }
            $sql=$total_sql;
            $total_db_result=$this->CI->db->query($sql)->result_array();
            $sql=$index_sql;
            
            if($select<>'')
                $sql.=' '.$select;
            $sql.=' '.$order;
            $sql.=" limit {$offset},{$per_page}";
            $db_result=$this->CI->db->query($sql)->result_array();
            
            $num_rows = $config['total_rows'] = $total_db_result[0]['total_count'];
            $this->CI->pagination->initialize($config);
            $page_link = $this->CI->pagination->create_links();
            $result=array('total'=>$total_db_result[0]['total_count'],'list'=>$db_result,'page'=>$page_link);
            return $result;
        }
  • 相关阅读:
    svn更改默认服务启动目录
    centos systemctl指令
    centos 安装mysql
    centos bad ELF interpreter: No such file or directory
    svn 设置post-commit后 报错svn: Can't convert string from 'UTF-8' to native encoding
    windows 下wamp环境3 安装php7
    windows 下wamp环境2 配置之mysql的安装
    windows 下wamp环境1 配置之apache的安装
    IE8 margin: auto 无法居中
    memcache安装
  • 原文地址:https://www.cnblogs.com/zhaobijin/p/5842780.html
Copyright © 2020-2023  润新知