Hướng dẫn what is the use of mysqli_num_rows? - việc sử dụng mysqli_num_rows là gì?

❮ Php mysqli tham khảo

Thí dụ

Trả về số lượng hàng trong một tập kết quả:

$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 = "Chọn tên cuối cùng, tuổi từ người đặt hàng theo tên cuối cùng";

if ($ result = mysqli_query ($ con, $ sql)) & nbsp; {& nbsp; // Trả về số lượng hàng trong tập kết quả & nbsp; $ rowCount = mysqli_num_rows ($ result); & nbsp; printf ("tập kết quả có %d hàng. \ n", $ rowCount); & nbsp; // Đặt kết quả miễn phí & nbsp; mysqli_free_result ($ result); & nbsp; }
  {
  // Return the number of rows in result set
  $rowcount=mysqli_num_rows($result);
  printf("Result set has %d rows.\n",$rowcount);
  // Free result set
  mysqli_free_result($result);
  }

mysqli_close ($ con); ?>
?>


Định nghĩa và cách sử dụng

Hàm mysqli_num_rows () trả về số lượng hàng trong một tập kết quả.


Cú pháp

Giá trị tham số

Tham sốSự mô tả
kết quảYêu cầu. Chỉ định một định danh tập kết quả được trả về bởi mysqli_query (), mysqli_store_result () hoặc mysqli_use_result ()

Chi tiết kỹ thuật

Giá trị trở lại:Trả về số lượng hàng trong tập kết quả
Phiên bản PHP:5+

❮ Php mysqli tham khảo


mysqli_num_rows

(Php 5, Php 7, Php 8)

mysqli_result :: $ num_rows - mysqli_num_rows - Nhận số lượng hàng trong tập kết quả -- mysqli_num_rowsGets the number of rows in the result set

Sự mô tả

Phong cách hướng đối tượng

Phong cách thủ tục

Hành vi của MySQLI_NUM_ROWS () phụ thuộc vào việc các bộ kết quả được đệm hay không bị ảnh hưởng đang được sử dụng. Hàm này trả về 0 cho các bộ kết quả không bị truy cập trừ khi tất cả các hàng đã được tìm nạp từ máy chủ.mysqli_num_rows() depends on whether buffered or unbuffered result sets are being used. This function returns 0 for unbuffered result sets unless all rows have been fetched from the server.

Trả về giá trị

Một INT đại diện cho số lượng hàng được tìm nạp. Trả về 0 ở chế độ không có máy tính trừ khi tất cả các hàng đã được tìm nạp từ máy chủ.int representing the number of fetched rows. Returns 0 in unbuffered mode unless all rows have been fetched from the server.

Ghi chú::

Nếu số lượng hàng lớn hơn PHP_INT_MAX, số sẽ được trả về dưới dạng chuỗi.PHP_INT_MAX, the number will be returned as a string.

Ví dụ

Ví dụ #1 Phong cách hướng đối tượng

mysqli_report

(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost""my_user""my_password""world");$result $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name");/* Get the number of rows in the result set */
$row_cnt $result->num_rows;printf("Result set has %d rows.\n"$row_cnt);

Ví dụ #2 Phong cách thủ tục

mysqli_report

(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT);
$link mysqli_connect("localhost""my_user""my_password""world");$result mysqli_query($link"SELECT Code, Name FROM Country ORDER BY Name");/* Get the number of rows in the result set */
$row_cnt mysqli_num_rows($result);printf("Result set has %d rows.\n"$row_cnt);

Các ví dụ trên sẽ xuất ra:

Ghi chú

Ghi chú::

Nếu số lượng hàng lớn hơn PHP_INT_MAX, số sẽ được trả về dưới dạng chuỗi.mysqli_stmt_num_rows() function, this function doesn't have object-oriented method variant. In the object-oriented style, use the getter property.

Ví dụ

  • Ví dụ #1 Phong cách hướng đối tượng
  • Ví dụ #2 Phong cách thủ tục
  • Các ví dụ trên sẽ xuất ra:
  • Ghi chú
  • Trái ngược với hàm mysqli_stmt_num_rows (), hàm này không có biến thể phương thức hướng đối tượng. Trong kiểu hướng đối tượng, sử dụng thuộc tính Getter.

Xem thêm

mysqli_affected_rows () - Nhận số lượng hàng bị ảnh hưởng trong hoạt động MySQL trước đó

If you have problems making work this num_rows, you have to declare ->store_result() first.

00

01

02

mysqli_store_result () - chuyển kết quả được đặt từ truy vấn cuối cùng

mysqli_use_result () - Bắt đầu truy xuất tập hợp kết quả

03

04

05

mysqli_query () - thực hiện truy vấn trên cơ sở dữ liệu

MySQLI_STMT_NUM_ROWS () - Trả về số lượng hàng được tìm nạp từ máy chủ

06

Mục đích của mysqli_num_rows () là gì?

Hàm mysqli_num_rows () trả về số lượng hàng trong một tập kết quả.returns the number of rows in a result set.

Việc sử dụng mysqli_fetch_assoc là gì?

Hàm mysqli_fetch_assoc () được sử dụng để trả về một mảng kết hợp đại diện cho hàng tiếp theo trong tập kết quả cho kết quả được biểu thị bằng tham số kết quả, trong đó mỗi khóa trong mảng biểu thị tên của một trong các cột của bộ kết quả.to return an associative array representing the next row in the result set for the result represented by the result parameter, where each key in the array represents the name of one of the result set's columns.

Mysqli_query là gì?

Định nghĩa và sử dụng hàm truy vấn () / mysqli_query () thực hiện truy vấn đối với cơ sở dữ liệu.performs a query against a database.

Chức năng mysql_fetch_row làm gì?

mysql_fetch_row () truy xuất hàng tiếp theo của tập kết quả: Khi được sử dụng sau mysql_store_result (), mysql_fetch_row () trả về null nếu không còn hàng để truy xuất.retrieves the next row of a result set: When used after mysql_store_result() , mysql_fetch_row() returns NULL if there are no more rows to retrieve.