我正在与域中的所有用户构建一个表。我让表格工作,并在其中放了一些分页代码,但现在我不断收到错误......
//connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Aantal per page
$num_rec_per_page=30;
//check connection
if ($conn->connect_error) {
die("Connection failed:" . $conn->connect_error);
}
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $num_rec_per_page;
$sql = "SELECT firstname, lastname, phone, department FROM tl_member ORDER BY lastname ASC LIMIT 30";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><br><hr><th align='left'>Naam</th><th align='center'>telefoon</th><th align='right' >afdeling</th></tr>";
// output data in rows
while($row = $result->fetch_assoc()) {
echo "<tr><td align='left'>" .$row["firstname"].", " .$row["lastname"]."</td><td align='center'>". $row["phone"]."</td><td align='right'>". $row["department"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$sql = "SELECT * FROM tl_member";
$rs_result = mysqli_query($sql); //run the query
$total_records = mysqli_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
echo "<a href='pagination.php?page=-1'>".'|<'."</a> "; // Goto 1st page
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
};
echo "<a href='pagination.php?page=$total_pages'>".'>|'."</a> "; // Goto last page
$conn->close();
?>
我得到的错误是:
警告:mysqli_query() 需要至少 2 个参数,其中 1 个在第 56 行的 C:\xampp\htdocsew\pagination.php 中给出
警告:mysqli_num_rows() 期望参数 1 mysqli_result,在第 57 行的 C:\xampp\htdocsew\pagination.php 中给出空
我不知道我做错了什么。
来自 PHP 参考:
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
第一个参数应该是 mysqli 资源链接,第二个参数应该是查询;
$rs_result = mysqli_query($conn, $sql); //run the query