php学习笔记(13):PHP+MYSQL简单分页

conn.php

<?php
/*
 * Created on 2010-1-6
 * Author:CHAUVET
 * Function:连接字符串
 */
 $conn=@mysql_connect("localhost","root","")or die("连接数据库出错!");
 mysql_select_db("newdb",$conn);
 mysql_query("set names 'gb2312'");

 function ReplaceSomeWords($words){
  $words=str_replace("/n","<br/>",str_replace(" ","&nbsp;",$words));
  return $words;
 }
?>

list.php

<?php
/*
 * Created on 2010-1-7
 * Author: CHAUVET
 * Function:
 */
 include("conn.php");
 $pageSize=5;
 $url=$_SERVER["REQUEST_URI"];
 $url=parse_url($url);
 $url=$url[path];

$numq=mysql_query("select * from `splitpage`");
$num=mysql_num_rows($numq);

if($_GET[page]){
 $pageval=$_GET[page];
 $page=($pageval-1)*$pageSize;
 $page.=',';
}
if($num>$pagesize){
 if($pageval<=1){
  $pageval=1;
 }
 echo "共 $num 条 "."<a href=$url?page=".($pageval-1).
">上一页</a> <a href=$url?page=".($pageval+1).">下一页</a>";
}
$sql="select * from `splitpage` limit $page $pageSize";
$query=mysql_query($sql,$conn);
while($row=mysql_fetch_array($query)){
 echo("<hr/>".$row['id']." | ".$row["name"]." | ".$row[sex]);
}
?>

posted @ 2010-01-07 20:13  静文·辅神  阅读(65)  评论(0编辑  收藏  举报