array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'it', ), 'this' => array ( 0 => 'mysqli-result.num-rows.php', 1 => 'mysqli_result::$num_rows', 2 => 'Gets the number of rows in the result set', ), 'up' => array ( 0 => 'class.mysqli-result.php', 1 => 'mysqli_result', ), 'prev' => array ( 0 => 'mysqli-result.lengths.php', 1 => 'mysqli_result::$lengths', ), 'next' => array ( 0 => 'class.mysqli-driver.php', 1 => 'mysqli_driver', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/mysqli/mysqli_result/num-rows.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PHP 5, PHP 7, PHP 8)
mysqli_result::$num_rows -- mysqli_num_rows — Gets the number of rows in the result set
Stile orientato agli oggetti
Stile procedurale
Returns the number of rows in the result set.
The behaviour of 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.
result
Solo nello stile procedurale: un identificatore di resultset restituito da mysqli_query(), mysqli_store_result() o mysqli_use_result().
An int representing the number of fetched rows.
Returns 0
in unbuffered mode unless all rows have been
fetched from the server.
Nota:
If the number of rows is greater than
PHP_INT_MAX
, the number will be returned as a string.
Example #1 Stile orientato agli oggetti
<?php
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);
Example #2 Stile procedurale
<?php
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);
I precedenti esempi visualizzeranno:
Result set has 239 rows.
Nota:
In contrast to the mysqli_stmt_num_rows() function, this function doesn't have object-oriented method variant. In the object-oriented style, use the getter property.