php count sql rows code example
Example 1: php num rows
<?php
$con = mysqli_connect("localhost", "root", "", "testing");
if (mysqli_connect_errno()) {
echo "Database connection failed.";
}
$query = "SELECT Username, Password FROM users";
$result = mysqli_query($con, $query);
if ($result) {
$row = mysqli_num_rows($result);
if ($row) {
printf("Number of row in the table : " . $row);
}
mysqli_free_result($result);
}
?>
Example 2: php mysqli number row
mysqli_num_rows($result);
Example 3: get count sql query in php
$result=mysql_query("SELECT count(*) as total from Students");
$data=mysql_fetch_assoc($result);
echo $data['total'];
Example 4: count sql query in php
$sql = "SELECT COUNT(*) AS total from Members";
$result = $conn->query($sql);
$data = $result->fetch_assoc();
echo $data['total'];