Need the number of rows of a table.
$st = $db->query("select count(*) from images");
$total = $st->rowCount();
echo $total;
result - 1
The table images
has 2430
rows.
How to get the correct number of rows?
Need the number of rows of a table.
$st = $db->query("select count(*) from images");
$total = $st->rowCount();
echo $total;
result - 1
The table images
has 2430
rows.
How to get the correct number of rows?
using PDO you could use
$result = $con->prepare("select count(*) from images");
$result->execute();
$total = $result->fetchColumn();
echo $total;
assuming $con is your connection to db
from PHP doc
DOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.
If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.
Using PHP and MYSQLi functions
$query = "select * from images";
$result = mysqli_query($db, $query);
echo mysqli_num_rows($result);
This will output the total number of rows in the table
Of Course this presupposes that a connection has already been established to the database using $db