num_rows, number or records in result">
num_rows reports the number of rows in a buffered result set returned by a query such as SELECT.
<?php
$result = $connection->query('SELECT id FROM student');
echo 'Rows: ' . $result->num_rows;
?>Current example first; the detailed examples below are retained for additional learning and comparison.
<?php
require "config.php";// Database connection file.
$query="select * from student ";
if ($result_set = $connection->query($query)) {
<span class='text-danger'>echo "Total No. of records :".$result_set->num_rows;</span>
$result_set->close();
}?>
Total No. of records :35
$result_set->num_rows;
mysqli_num_rows($result_set)
The input parameter $result_set is the output of result set identifier of mysqli_query(), mysqli_store_result() or mysqli_use_result().
MySQLI database connection file
Example : Object Oriented Style<?php
require "config.php";//<span class='text-success'> Database connection file.</span>
$query="select * from student ";
if ($result_set = $connection->query($query)) {
echo "Total No. of records :".$result_set->num_rows;
$result_set->close();
}?>
Total No. of records :35
Procedural style
<?php
require "config.php";// <span class='text-success'>Database connection file.</span>
$query="select * from student ";
if ($result_set = mysqli_query($connection,$query)) {
<span class='text-danger'>echo "Total No. of records :".mysqli_num_rows($result_set);</span>
mysqli_free_result($result_set);
}
?>
Total No. of records :35
With bind_param & using variables
$class='Three';
$query="select * from student WHERE class=? ";
$stmt=$connection->prepare($query);
$stmt->bind_param('s', $class);
$stmt->execute();
$stmt->store_result();
echo "Total No. of records :".$stmt->num_rows;
$t="SELECT * FROM istudent where mark >90";
$check=$connection->query($t);
if(mysqli_num_rows($check)>0){
// record found
}else{
// No record found
}
MYSQLI Functions
mysqli_fetch_array()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.