save.bz
Search

PHP mysqli count total number of rows in table

1 week ago  •  564 views
PHP mysqli count total number of rows in table

<?php

if ($CountRows = $mysqli->query("SELECT name FROM tablename WHERE id= '1'")) {
$TotalRows = $CountRows->num_rows;
$CountRows->close();
} else {
printf("Error: %sn", $mysqli->error);
}

echo $TotalRows;


// OR

if ($Pages = $mysqli->query("SELECT id FROM pages")) {
$TotalPages = $Pages->num_rows;
$Pages->close();
} else {
printf("Error: %sn", $mysqli->error);
}
echo $TotalPages;

// OR

$Total = $mysqli->query("SELECT * FROM tablename WHERE id = '4'");
$TotalCount = $Total->num_rows;

echo $TotalCount;
?>