Query: mysqli_num_rows
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
MYSQLI_NUM_ROWS(3) 1 MYSQLI_NUM_ROWS(3) mysqli_result::$num_rows - Gets the number of rows in a result Object oriented styleSYNOPSISint$mysqli_result->num_rows ()DESCRIPTIONProcedural style int mysqli_num_rows (mysqli_result $result) Returns the number of rows in the result set. The behaviour of mysqli_num_rows(3) depends on whether buffered or unbuffered result sets are being used. For unbuffered result sets, mysqli_num_rows(3) will not return the correct number of rows until all the rows in the result have been retrieved.PARAMETERSo $ result -Procedural style only: A result set identifier returned by mysqli_query(3), mysqli_store_result(3) or mysqli_use_result(3).RETURN VALUESReturns number of rows in the result set. Note If the number of rows is greater than PHP_INT_MAX, the number will be returned as a string.EXAMPLESExample #1 Object oriented style <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } if ($result = $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name")) { /* determine number of rows result set */ $row_cnt = $result->num_rows; printf("Result set has %d rows. ", $row_cnt); /* close result set */ $result->close(); } /* close connection */ $mysqli->close(); ?> Example #2 Procedural style <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) { /* determine number of rows result set */ $row_cnt = mysqli_num_rows($result); printf("Result set has %d rows. ", $row_cnt); /* close result set */ mysqli_free_result($result); } /* close connection */ mysqli_close($link); ?> The above examples will output: Result set has 239 rows.SEE ALSOmysqli_affected_rows(3), mysqli_store_result(3), mysqli_use_result(3), mysqli_query(3). PHP Documentation Group MYSQLI_NUM_ROWS(3)