Giel Evens Giel Evens - 10 months ago 47
MySQL Question

Count how many rows you have in your db with PHP


I want to count how many rows i have in a table. I got a table (workstations) in my mysql database (phpmyadmin). I want to print it out, so ik can see how many workstations their are "active" in my environment

I've read many blogs about this, but all the things they propose are not working for me.

Thanks in advance!


Use COUNT(*)

You can see here:

SELECT COUNT(*) FROM table_name;


$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$query = "SELECT COUNT(*) FROM table_name";
$result = mysqli_query($mysqli,$query);
$rows = mysqli_fetch_row($result);
echo $rows[0];