Answers for "count number of rows in mysql query result in php"

PHP
1

php 7 count result in database

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("host", "username", "password","db_name");
mysqli_set_charset($link, "utf8mb4");

$result = mysqli_query($link, "SELECT count(*) FROM blackandwhite");
$num_rows = mysqli_fetch_row($result)[0];

echo "$num_rows Rows\n";
Posted by: Guest on November-18-2020
1

php num rows

<?php 
/*
Explination 
The mysqli_num_rows() function is an inbuilt function in PHP 
which is used to return the number of rows present in the result set. 
It is generally used to check if data is present in the database or not. 
To use this function, it is mandatory to first set up the connection with the MySQL database.
*/
	// Setting up connection with database Geeks 
	$con = mysqli_connect("localhost", "root", "", "testing"); 
	
	// Check connection 
	if (mysqli_connect_errno()) { 
		echo "Database connection failed."; 
	} 
	// Fetch Query
	$query = "SELECT Username, Password FROM users"; 
	
	// Execute the query and store the result set 
	$result = mysqli_query($con, $query); 
	
	if ($result) { 
		// it return number of rows in the table. 
		$row = mysqli_num_rows($result); 
		if ($row) { 
			 	printf("Number of row in the table : " . $row); 
			} 
		// close the result. 
		mysqli_free_result($result); 
	} 

// Output : Number of row in the table : 5
?>
Posted by: Guest on June-15-2020

Code answers related to "count number of rows in mysql query result in php"

Browse Popular Code Answers by Language