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//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
1SELECT row_number() over ( order by firstName) RowNumberSqeuence,FirstName from rowNumberDemo
2 order by FirstName;
1SET @row_number = 0;
2SELECT
3 (@row_number:=@row_number + 1) AS num,
4 firstName,
5 lastName
6FROM
7 employees
8ORDER BY firstName, lastName
9LIMIT 5;