取总数:
Select SQL_BUFFER_RESULT count(col1) as all_ID from foods;
开始: start = 0
每页长度: page_length = 16
总页数: pages = all_ID/page_length
最后一页的记录数: odd = all_ID%page_length
查询当前页:
set @rownum=0;
select SQL_BUFFER_RESULT id,title,url,img,price
from foods,
( select my_id from
( select id as my_id,(@rownum:=@rownum+1) as row_id from foods
order by modified desc
) as tmp
where row_id between '@{int:1+start}'
and '@{int:start+page_length}'
) as temp
where my_id=id
实际效果:
http://www.dfwgw.com/dGFva2UvbGlzdF9hbGwuaHRtbA==url.html
表结构参考:
CREATE TABLE `foods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`url` varchar(100) NOT NULL,
`catalog` int(11) NOT NULL DEFAULT '0',
`img` varchar(120) DEFAULT NULL,
`price` double DEFAULT '0',
`des` text,
`modified` datetime NOT NULL,
`sold_num` int(11) NOT NULL DEFAULT '0',
`location` varchar(28) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `catalog` (`catalog`),
KEY `modified` (`modified`),
KEY `sold_num` (`sold_num`),
FULLTEXT KEY `title` (`title`)
)