DELIMITER $$;
DROP PROCEDURE IF EXISTS `myweb`.`gettopiclist`$$
CREATE PROCEDURE `myweb`.`gettopiclist` (in classid int,
in page int,
in pagesize int,
out acount int)
BEGIN
set @startrow=(page-1)*pagesize;
set @p1 = @startrow;
set @p2 = pagesize;
set @p3 = classid;
set @query='select id,title,postdate,revertnum,clicknum,uid,username
from posttopic where id<=(select id from posttopicview ';
if classid=0 then
set @query=concat(@query,' order by postdate desc limit ?,1)
order by postdate desc limit ?;');
prepare querystr from @query;
execute querystr using @p1,@p2;
set acount=(select count(id) from posttopicview);
else
set @query=concat(@query,' where cid=? order by postdate desc limit ?,1)
order by postdate desc limit ?;');
prepare querystr from @query;
execute querystr using @p3,@p1,@p2;
set acount=(select count(id) from posttopicview where cid=classid);
end if;
deallocate prepare querystr;
END$$
DELIMITER ;$$