06/04/2021, 14:46
Hàm mysqli_num_rows() trong PHP - PHP Function
Code $con=mysqli_connect("localhost","my_user","my_password","my_db"); // Check connection if (mysqli_connect_errno()){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname"; if ($result=mysqli_query($con,$sq ...
Hàm mysqli_num_rows() sẽ trả về số hàng trong tập hợp kết quả truyền vào.
Cú pháp
Cú pháp: mysqli_num_rows( $result);
Trong đó:
$resultlà tập hợp kết quả trả về từ các hàmmysqli_query(),mysqli_store_result()hoặcmysqli_use_result().
Kết quả trả về
Hàm sẽ trả về số nguyên đại diện cho số hàng có trong kết quả.
Ví dụ
Cách sử dụng hàm mysqli_num_rows():
Code
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql)){
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
printf("Result set has %d rows.
",$rowcount);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);Tham khảo: w3schools.com
Nguồn: Zaidap.com.net