lib/Action/SqlAction.class.php
class SqlAction extends Action{
public function pagesql($page=1,$limit=10,$step=5){
$list=M('attach');
$this->page=$page;
$this->start=($page-ceil($step/2))>0?($page-floor($step/2)):1;
$this->count=(int)($list->count()/$limit);
if(($page+$step)>$this->count){
$this->start=$this->count-$step;
$this->end=$this->count;
}else{
$this->end=$this->start+$step;
}
$this->step=$step;
$this->data=$list->page("$page,$limit")->order("id asc")->select();
$this->display();
}
}
Tpl/Sql/pagesql.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<foreach name="data" item="j" key="k">
{$j.id}-{$j.name}<br>
</foreach>
<php>
for ($i=$start;$i<$end;$i++){
if($page!=$i){
echo "<a href='__URL__/pagesql/page/".$i."'>第".$i."页</a> ";
}else{
echo "第".$i."页 ";
}
}
</php>
</body>
</html>
/Sql/pagesql