PHP分页

<?php

$conn=mysql_connect("localhost","root","");

//$result2=mysql_db_query("hello_world", "insert into hello_table values (‘add1‘,8)",$conn);

// $result2=mysql_db_query("hello_world", "delete from hello_table where hello_column=‘add1‘",$conn);

$resultNum=mysql_db_query("hello_world","select count(*) from hello_table order by hello_column" ,$conn);

$RSS=mysql_fetch_array($resultNum);

$num=$RSS[0];

if(empty($_GET[‘page‘])){

$page=0;

}else{

$page=$_GET[‘page‘];

if($page<0){

$page=0;

}

if($page>=ceil($num/5)){

$page=ceil($num/5)-1;

}

 

}

$excute="select * from hello_table order by hello_column limit ".($page*5).",5 ";

$result=mysql_db_query("hello_world",$excute ,$conn);

$row=mysql_fetch_row($result);

for($i=0;$i<mysql_num_fields($result);$i++){

echo mysql_field_name($result, $i)." ";

}

echo "<br>";

while($row=mysql_fetch_row($result)){

for($i=0;$i<mysql_num_fields($result);$i++){

echo $row[$i]." ";

}

echo "<br>";

}

mysql_free_result($result);

mysql_close($conn);

 

 

?>

<

a href="test.php?page=0">FirstPage</a>

<

a href="test.php?page=<?=($page-1) ?>">PrevPage</a>

<

a href="test.php?page=<?=($page+1) ?>">NextPage</a>

<

a href="test.php?page=<?=ceil($num/5)-1 ?>">LastPage</a>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。