我如何把php得到的数据进行分类呢?
<?php<br />$con = mysql_connect("localhost","root","123");<br />if (!$con)<br /> {<br /> die('Could not connect: ' . mysql_error());<br /> }<br /><br />mysql_select_db("task", $con);<br />mysql_query("set names utf8");<br /><br />$result = mysql_query("SELECT * FROM tesk limit 0,10 ");<br /><br />echo "<table border='1'><br /><tr><br /><th>time</th><br /><th>id</th><br /><th>name</th><br /><th>task</th><br /><th>remark</th><br /></tr>";<br /><br />while($row = mysql_fetch_array($result)){<br /> echo "<tr>";<br /> echo "<td>" . $row['date'] . "</td>";<br /> echo "<td>" . $row['id'] . "</td>";<br /> echo "<td>" . $row['name'] . "</td>";<br /> echo "<td>" . $row['task'] . "</td>";<br /> echo "<td>" . $row['remark'] . "</td>";<br /> echo "</tr>";<br /> }<br />echo "</table>";<br /><a herf=“”>下一页</a> <br />mysql_close($con);<br /><br />?>
class PageTool{<br /> protected $total=0;<br /> protected $perpage=10;<br /> protected $page=1;<br /><br /> /*构造函数的参数分别为商品总条目数,每页多少条目,当前页*/<br /> public function __construct($total,$page=false,$perpage=false){<br /> $this->total = $total;<br /> if($perpage){<br /> $this->perpage = $perpage;<br /> }<br /> if($page){<br /> $this->page = $page;<br /> }<br /> }<br /><br /> public function show(){<br /> $cnt = ceil($this->total/$this->perpage);//$cnt表示一共需要多少页<br /> $uri = $_SERVER['REQUEST_URI']; //从地址栏获取URL<br /> $parse = parse_url($uri); //将获取的URL变成特定数组<br /> //print_r($parse);exit;<br /> $param = array();<br /> if(isset($parse['query'])){ //如果地址栏传了参数(也就是url?之后的字符串),则获取参数放入$param数组中<br /> parse_str($parse['query'],$param);<br /> }<br /><br /> <br /> /*不管地址栏有没有传page参数,都要把page从$param中剔除<br /> 因为page参数是需要计算出来的,不能定死*/<br /> unset($param['page']);<br /><br /> $url = $parse['path'].'?';<br /> if(!empty($param)){<br /> $param = http_build_query($param); //把数组$param再变成字符串,这一次已经剔除了page参数<br /> $url = $url.$param.'&'; //重新拼凑$url,最后的&符号用于连接计算出的page<br /> }<br /><br /> /*<br /> 关键部分:计算页码导航<br /> 此处逻辑有点复杂,多思考下<br /> */<br /> $nav = array(); //用于存放最终地址栏链接<br /> $nav[0] = '<span class="page_now">'.$this->page.'</span>'; //把当前地址栏的page参数放入$nav数组<br /> for($left=$this->page-1,$right=$this->page+1;<br /> ($left>=1<br><font color='#FF8000'>------解决思路----------------------</font><br>$right<=$cnt)&&count($nav)<=5;){<br /> if($left>=1){<br /> array_unshift($nav, '<a href="'.$url.'page='.$left.'">'.'['.$left.']'.'</a>');<br /> $left-=1;<br /> }<br /><br /> if($right<=$cnt){<br /> array_push($nav, '<a href="'.$url.'page='.$right.'">'.'['.$right.']'.'</a>');<br /> $right+=1;<br /> }<br /> }<br /><br /> return implode('', $nav);<br /> }<br /><br />}<br /><br />/*<br /> 测试分页类效果<br /> $page = isset($_GET['page'])?$_GET['page']:1;<br /> $pagetool = new PageTool(20,$page,6);<br /> echo $pagetool->show();<br />*/