Browsed by
月份:2012年8月

php+mysql分页练习

php+mysql分页练习

php+mySql 分页练习

1.$url = $_SERVER[‘REQUEST_URI’];

2.$page = $_GET[page];

3.SELECT * FROM `message` limit $pageindex $pageSize

 

[codesyntax lang=”php”]

<?
include ("conn.php");

$pageSize = 4;
$pageindex = "0,";

$total = mysql_query("SELECT count(1) FROM `message`");
echo $total;
if ($_GET[page]) {
	$page = $_GET[page];
	$page = $page < 0 ? 0 : $page;
	$page = $page >= $total ? $total -1 : $page;

	$pageindex = $page * $pageSize;
	$pageindex .= ",";
}

$url = $_SERVER['REQUEST_URI'];
$url = parse_url($url);
$url = $url[path];

echo "<a href=$url?page=" . ($page -1) . ">上一页</a>" . "&nbsp|&nbsp<a href=$url?page=" . ($page +1) . ">下一页</a>";

$sql = "SELECT * FROM `message` limit $pageindex $pageSize";
$r = mysql_query($sql);

echo " 总页数" . $total . "<br><hr>";
while ($ss = mysql_fetch_array($r)) {
	echo $ss[user] . "<br><hr>";
}

?>

[/codesyntax]