<?php require_once 'login.php'; $num_rec_per_page=2; // 每页显示数量 //mysql_connect('localhost','jim','0000'); // 数据库连接 //mysql_select_db('publications'); // 数据库名 $conn = new mysqli($db_hostname, $db_username, $db_password, $db_database); if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $query = "SELECT * FROM user LIMIT $start_from, $num_rec_per_page"; //$rs_result = mysql_query ($sql); // 查询数据 $result = $conn->query($query); ?> <table> <tr><td>Name</td><td>Phone</td></tr> <?php //while ($row = mysql_fetch_assoc($result)) { while ($row = $result->fetch_array(MYSQLI_NUM)) { ?> <tr> <td><?php echo $row[0]; ?></td> <td><?php echo $row[1]; ?></td> </tr> <?php }; ?> </table> <?php $sql = "SELECT * FROM user"; $result = $conn->query($sql); //查询数据 $total_records = mysqli_num_rows($result); // 统计总共的记录条数 $total_pages = ceil($total_records / $num_rec_per_page); // 计算总页数 echo "<a href='fenyetest.php?page=1'>".'|<'."</a> "; // 第一页 for ($i=1; $i<=$total_pages; $i++) { echo "<a href='fenyetest.php?page=".$i."'>".$i."</a> "; }; echo "<a href='fenyetest.php?page=$total_pages'>".'>|'."</a> "; // 最后一页,注意把网址改到当前页 ?>
注意mysql与mysqli的不同