How to Count Number of Rows in PHP MySQL?

03-Apr-2023

.

Admin

How to Count Number of Rows in PHP MySQL?

Hi Dev,

This tutorial is focused on how to count the number of rows in PHP MySQL. you'll learn how to count a number of rows in the PHP MySQL. We will use how to count the number of rows in PHP MySQL. if you have a question about how to count the number of rows in the PHP MySQL then I will give a simple example with a solution.

Now, let's see the article on how to count a number of rows in the PHP MySQL. it's a simple example of how to count the number of rows in PHP MySQL. you can understand the concept of how to count the number of rows in PHP MySQL. if you have a question about how to count the number of rows in PHP MySQL then I will give a simple example with a solution.

Example:


index.php

<?php

$servername = "localhost";

$username = "root";

$password = "root";

$dbname = "myDB";

// Create a connection

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check the connection

if (!$conn) {

die("Connection failed: " . mysqli_connect_error());

}

$sql = "SELECT * FROM students";

if ($result = mysqli_query($conn, $sql)) {

// Return the number of rows in the result set

$rowcount = mysqli_num_rows( $result );

// Display the result

printf("Total number of rows : %d\n", $rowcount);

}

?>

Output:

Total number of rows: 10

I hope it could help you...

#PHP