1<?php
2/*
3Explination
4The mysqli_num_rows() function is an inbuilt function in PHP
5which is used to return the number of rows present in the result set.
6It is generally used to check if data is present in the database or not.
7To use this function, it is mandatory to first set up the connection with the MySQL database.
8*/
9 // Setting up connection with database Geeks
10 $con = mysqli_connect("localhost", "root", "", "testing");
11
12 // Check connection
13 if (mysqli_connect_errno()) {
14 echo "Database connection failed.";
15 }
16 // Fetch Query
17 $query = "SELECT Username, Password FROM users";
18
19 // Execute the query and store the result set
20 $result = mysqli_query($con, $query);
21
22 if ($result) {
23 // it return number of rows in the table.
24 $row = mysqli_num_rows($result);
25 if ($row) {
26 printf("Number of row in the table : " . $row);
27 }
28 // close the result.
29 mysqli_free_result($result);
30 }
31
32// Output : Number of row in the table : 5
33?>
34
1// Fetch Query
2$query = "SELECT user_name from registered_users where user_name like '%ank%'";
3
4// Execute the query and store the result set
5$result = mysqli_query($con, $query);
6
7if ($result) {
8 // it return number of rows in the table.
9 $row = mysqli_num_rows($result);
10}
1//number of rows retrieved from a query
2<?php
3
4$link = mysql_connect("localhost", "mysql_user", "mysql_password");
5mysql_select_db("database", $link);
6
7$result = mysql_query("SELECT * FROM table1", $link);
8$num_rows = mysql_num_rows($result);
9
10echo "$num_rows Rows\n";
11
12?>
13
14
1<?php
2
3$link = mysql_connect("localhost", "mysql_user", "mysql_password");
4mysql_select_db("database", $link);
5
6$result = mysql_query("SELECT * FROM table1", $link);
7$num_rows = mysql_num_rows($result);
8
9echo "$num_rows Zeilen\n";
10
11?>