php ajax 分页四_PHP教程
最就是php的result.php文件喽,:
//一系列从数据库的查询造作这里就不多说了....自己参考以下就知道了
//PHP服务端
/*
PHP分页函数
function Ajaxpage($sql,$num){
global $db;
$pageno=$_GET['pageno'];
$pageno=(int)$pageno;
if(empty($pageno)||$pageno $result=$db->query($sql);
$number=$db->num_rows($result);
$totalpage=(int)ceil($number/$num);
if($pageno>=$totalpage){$pageno=$totalpage;}
$start_rowno=($pageno-1)*$num;
$query=$sql." LIMIT ".$start_rowno.",".$num;
$result=$db->query($query);
return array('result'=>$result,'page'=>array('pageno'=>$pageno,'totalpage'=>$totalpage,'number'=>$number));
}
$sql="select * from guest";//查询SQL语句
$num=2;//分页控制,每页显示2条记录
$return=Ajaxpage($sql,$num);
while($row=$db->fetch_assoc($return['result'])){
$result[]=$row; //这里可以用PHP处理下数据,这里就不举例了
}
$result=array('result'=>$result,'page'=>$return['page']);
include('json.class.php');//包含JSON类文件
$json=& new Json();
$result=$json->encode($result);//JSON
echo $result;
*/
//假如根据AJAX发来pageno参数从数据库得到的资源经过JSON后是$str这个样子,直接输出,让JS处理.
//如果有什么不明白的可以问我
if(ob_get_length()) ob_clean();
header('cache-control:no-cache,must-revalidate');
header('pragma:no-cache');
if($_GET['pageno']==1)
$str='{"result":[{"id":"99","name":"技术","qq":"","tel":"","email":"","content":"[emot:0]","time":"1198522490","ip":"127.0.0.1",
"rcontent":null,"rtime":"0","url":"0","img":"app/index/image/show/1.gif"},{"id":"100","name":"测试","qq":"","tel":"","email":"","content":"[emot:9]","time":1198548687","ip":"127.0.0.1","
rcontent":null,"rtime":"0","url":"0","img":"app/index/image/show/4.gif"}],"page":{"pageno":1,"totalpage":2,"number":2}}';
else
$str='{"result":[{"id":"101","name":"啊","qq":"","tel":"","email":"","content":"[emot:8][emot:1]","time":"1198548716","ip":"127.0.0.1","rcontent":null,"rtime":"0","url":"0","img":
"app/index/image/show/9.gif"}],"page":{"pageno":2,"totalpage":2,"number":3}}';
echo iconv('gb2312','utf-8',$str);
?>
上一篇: MySQL 测试 sql-bench 出错_MySQL
下一篇: 将信箱的某一段替换为