<?php //查询总页数 include ("db.class.php"); $db = new db(); $tj = " 1=1 "; if(!empty($_POST["name"])) { $name = $_POST["name"]; $tj = " name like '%{$name}%' "; } $sql = "select count(*) from min WHERE {$tj} "; $zts = $db->strquery($sql); //总条数 echo ceil($zts/3); //ceil向上取整
加载分页信息的页面:
<?php include ("db.class.php"); $db = new db(); $page=$_POST["page"]; //去当前页page $tj = " 1=1 "; if(!empty($_POST["name"])) { $name = $_POST["name"]; $tj = " name like '%{$name}%' "; } $num = 3; //每页显示几条 $tg = ($page-1)*3;//跳过几条 $sql = "select * from min where {$tj} limit {$tg},{$num}"; //limit:两个参数,第一个是跳过多少条,第二个是取多少条 $arr = $db->Query($sql); //遍历 $str=""; foreach ($arr as $v) { $str = $str.implode("-",$v)."|"; //用-把$v拼起来,拼出来是1-红2-蓝,用|分割,拼出来是1-红|2-蓝| } $str = substr($str,0,strlen($str)-1); //截取字符串:从第0个开始,截取它的长度-1 //strlen获取字符串长度 echo $str;