PHP+Mysql分页

<?php
$conn = mysql_connect ( "localhost", "root", "root" );
mysql_select_db ( "test", $conn );
mysql_query ( "set names 'UTF-8'" );

$showNum = 4;
if ($_GET ['goPageNum']) {
    $goPageNum = $_GET ['goPageNum'];
    if ($goPageNum <= 0)
        $goPageNum = 1;
} else {
    $goPageNum = 1;
}

$nowShowBeginNum = ($goPageNum - 1) * $showNum; // 索引0算第一条数据
$sel_message = "select * from message limit $nowShowBeginNum,$showNum";
$que_message = mysql_query ( $sel_message ) or die ( "Invalid query: " . mysql_error () );
?>


<form action="" method="get">
    <a href="?goPageNum=<?php echo ($goPageNum -1);?>">上一页</a> :<a href="?goPageNum=<?php echo ($goPageNum +1);?>">下一页</a><br/>
<?php
while ( $row_message = mysql_fetch_array ( $que_message ) ) {
    echo $row_message ['id'] . " : " . $row_message ['title'] . " : " . $row_message ['content'] . "<br>";
}
?>
</form>

 

posted @ 2012-03-13 22:37  风吹屁股凉冰冰  阅读(392)  评论(0编辑  收藏  举报