溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

PHP分頁

發(fā)布時間:2020-07-02 15:36:11 來源:網(wǎng)絡(luò) 閱讀:331 作者:zhuchengdie 欄目:web開發(fā)

<?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>

 =====================================================================

 

怎么分段,當(dāng)前在第幾段 (每頁有幾條,當(dāng)前再第幾頁

 

前10條記錄:select * from table limit 0,10

第11至20條記錄:select * from table limit 10,10

第21至30條記錄:select * from table limit 20,10

 

 

 

(當(dāng)前頁數(shù) - 1 )X 每頁條數(shù) , 每頁條數(shù)

Select * from table limit ($Page- 1) * $PageSize, $PageSize

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI