高手来看看!!1写了一段PHP代码做留言板 但不知道怎么实现分页显示 比如一页显示10条

<?php //-------[基本设定]-----------
$mysql_server_name ="localhost";
$mysql_username ="root";
$mysql_password ="123456";
$mysql_database ="albert";
//----------------------------------

//建立连线----透过(伺服器位置,使用者名称,使用者密码)
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

//准备好你的 SQL 语法
$sql="select `id`,`name`,`sex`,`email`,`info`,`ip`,`time at` from`gbook` order by `id` desc ";

mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql,$conn);

while($row=mysql_fetch_row($result))
{// print_r($row);
if ($row[2]==1)
{ $gender="大灰狼";
}
else
{ $gender="小红帽";
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.ys01 {
color: #0CF;
}
.YS01 {
color: #F00;
}
.ys02 {
color: #F90;
}
.ys03 {
color: #060;
}
.ys03 {
color: #060;
}
.y1 {
color: #0C0;
}
</style>
</head>
<body>
<table bordercolor="#0033FF" width="584" border="1" cellspacing="0">
<tr >
<td bgcolor="#33FFFF"height="34"><span class="ys02">(<?php echo $row[0] ?>) <?php echo $gender ?> <?php echo $row[1] ?>    </span>                  <span class="ys03">      ip:<?php echo $row[5] ?>     </span>               发表于<span class="YS01">  <?php echo $row[6] ?> </span></td>
</tr>
<tr>
<td height="99"><p> </p>
<p><?php echo nl2br($row[4]) ?> </p>
<p> </p>
<p> </p>
<p> </p></td>
</tr>
</table>
<hr align="left" width="584" noshade color="#000099" class="y1">
</body>
</html>

<?php

}
mysql_free_result($result);

?>

把sql改下
$sql="select `id`,`name`,`sex`,`email`,`info`,`ip`,`time at` from`gbook` order by `id` desc ";

select `id`,`name`,`sex`,`email`,`info`,`ip`,`time at` from`gbook` order by `id` desc LIMIT $StartRow,$PageSize"
StartRow---》起始页。PageSize---》显示条数

然后你再页面的下面定义一些 首页,上一页,下一页,尾页。跳到()页。
定义一些全局变量,记录当前第几页等。

php100上,有专门的学习例子,你可以看看
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-01-17
给你源码,
<center>
<?php
include("conn.php");
$pagesize=4;
$url = $_SERVER["REQUEST_URI"];
$url = parse_url($url);
$url = $url[path];

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

if($_GET[page]){

$pageval=$_GET[page];

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

mysql翻页都是用limit...........
第2个回答  2011-01-18
mysql翻页都是用limit...........
$intPerPage = 20;//每页的记录数。
$intPage = intval( $_GET['page']);
if ( $intPage < 1 ) { $intPage = 1;}
$intStart = ( $intPage - 1 ) * $intPerPage;

select `id`,`name`,`sex`,`email`,`info`,`ip`,`time at` from`gbook` order by `id` desc LIMIT $intStart ,$intPerPage"
$intStart ---》起始页记录数。$intPerPage---》每页的条数

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网