How to get count of rows in MySQL table using PHP?

You have a couple of options how to get the value of COUNT(*) from the SQL. The easiest three are probably this: $sql = “SELECT COUNT(*) FROM news”; $result = mysqli_query($con, $sql); $count = mysqli_fetch_assoc($result)[‘COUNT(*)’]; echo $count; or using column alias: $sql = “SELECT COUNT(*) as cnt FROM news”; $result = mysqli_query($con, $sql); $count = … Read more