這里給大家分享的是個人前段時間做了一個列表分頁的功能模塊(php分頁的功能模塊),非常的簡單實用,推薦給有需要的小伙伴參考下。
先貼張圖看看效果

在貼一下代碼吧
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <?php $localhost = "localhost"; $username = "root"; $password = "root"; $db = "test"; //信息 $pagesize = 5; $conn = mysql_connect($localhost,$username,$password); //鏈接數(shù)據(jù)庫 if(!$conn){ echo "數(shù)據(jù)庫鏈接失敗".mysql_error(); } mysql_query("SET NAMES 'UTF8'"); //編碼轉(zhuǎn)化 $db_select = mysql_select_db($db); //選擇表 //查詢記錄總數(shù) $total_sql = "select COUNT(*) from page"; $total_result = mysql_query($total_sql); $total_row_arr = mysql_fetch_row($total_result); $total_row = $total_row_arr[0]; //總條數(shù) //總頁數(shù) $total = ceil($total_row / $pagesize); //當(dāng)前頁數(shù) $page = @$_GET['p'] ? $_GET['p'] : 1; //limit 下限 $offset = ($page - 1)*$pagesize; $sql = "select * from page order by id limit {$offset},{$pagesize}"; $result = mysql_query($sql); echo "<p>PHP分頁代碼的小模塊</p>";新聞熱點
疑難解答
圖片精選