在PHP中,mysqli_num_rows函數用于獲取結果集中的行數。它的使用方式如下:
$conn = new mysqli("localhost", "username", "password", "database");
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);
$rowCount = mysqli_num_rows($result);
echo "總共有 " . $rowCount . " 行數據";
完整的示例代碼如下:
$conn = new mysqli("localhost", "username", "password", "database");
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);
$rowCount = mysqli_num_rows($result);
echo "總共有 " . $rowCount . " 行數據";
注意:在使用mysqli_num_rows函數之前,需要先執行mysqli_query函數來執行查詢并獲取結果集。使用mysqli_num_rows函數之前,還需要確保數據庫連接已經建立。