MySQL pagination stored procedure
Nov 12, 2016 am 09:36 AM/* --名称:MYSQL版查询分页存储过程 --输入参数:@fields -- 要查询的字段用逗号隔开 --输入参数:@tables -- 要查询的表 --输入参数:@where -- 查询条件 --输入参数:@orderby -- 排序字段 --输出参数:@page -- 当前页计数从1开始 --输出参数:@pagesize -- 每页大小 --输出参数:@totalcount -- 总记录数 --输出参数:@pagecount -- 总页数 --输出参数:_sumfields -- 统计字段 */ DROP PROCEDURE IF EXISTS Proc_Page; CREATE PROCEDURE Proc_Page ( in _fields varchar(2000), in _tables text, in _where varchar(2000), in _orderby varchar(200), in _pageindex int, in _pagesize int, in _sumfields varchar(200), out _totalcount int , out _pagecount int ) begin set @startRow = _pageSize*(_pageIndex -1); set @pageSize = _pageSize; set @rowindex = 0; set @strsql = CONCAT('select sql_calc_found_rows @rowindex:=@rowindex+1 as rownumber,',_fields,' from ',_tables,case ifnull(_where,'') when '' then '' else concat(' where ',_where) end,' order by ',_orderby,' limit ',@startRow,',',@pageSize); prepare strsql from @strsql; execute strsql; deallocate prepare strsql; set _totalcount = found_rows(); if (_totalcount <= _pageSize) then set _pagecount = 1; else if (_totalcount % _pageSize > 0) then set _pagecount = _totalcount / _pageSize + 1; else set _pagecount = _totalcount / _pageSize; end if; end if; if(ifnull(_sumfields,'') <> '') then set @sumsql = contact('select ',_sumfields,' from ',_tables,case ifnull(_where,'') when '' then '' else concat(' where ',_where) end); prepare sumsql from @sumsql; execute sumsql; deallocate prepare sumsql; end if; end
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?
3 weeks ago
By 王林
Two Point Museum: All Exhibits And Where To Find Them
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?
3 weeks ago
By 王林
Two Point Museum: All Exhibits And Where To Find Them
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library

Run MySQl in Linux (with/without podman container with phpmyadmin)

What is SQLite? Comprehensive overview

Running multiple MySQL versions on MacOS: A step-by-step guide

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?

How do I configure SSL/TLS encryption for MySQL connections?
