But find some on the internet, found that there is a feature-that is, the total number of records can not be outgoing, simply study it yourself. At last, the efficiency may not be very good, but I feel good too. Post code directly: It's also a record of learning MySQL for yourself.
Copy Code code as follows:
CREATE PROCEDURE P_pagelist
(
M_pageno int,
m_perpagecnt int,
M_column varchar (1000),
M_table varchar (1000),
M_condition varchar (1000),
M_orderby varchar (200),
Out m_totalpagecnt int
)
BEGIN
SET @pageCnt = 1; --Total number of records
SET @limitStart = (m_pageno-1) *m_perpagecnt;
SET @limitEnd = m_perpagecnt;
SET @sqlCnt = CONCAT (' Select COUNT (1) into @pageCnt from ', m_table); --This statement is critical to get the total value
SET @sql = CONCAT (' Select ', M_column, ' from ', m_table);
IF M_condition is not NULL and m_condition <> ' THEN
SET @sql = CONCAT (@sql, ' where ', m_condition);
SET @sqlCnt = CONCAT (@sqlCnt, ' where ', m_condition);
End IF;
IF M_orderby is not NULL and M_orderby <> ' THEN
SET @sql = CONCAT (@sql, ' ORDER by ', M_orderby);
End IF;
SET @sql = CONCAT (@sql, ' limit ', @limitStart, ', ', @limitEnd);
PREPARE s_cnt from @sqlCnt;
EXECUTE s_cnt;
Deallocate PREPARE s_cnt;
SET m_totalpagecnt = @pageCnt;
PREPARE record from @sql;
EXECUTE record;
Deallocate PREPARE Record;
End