I'm trying to count the number of rows in several tables and echo the results individually. I've tried using the below script and it returns the original value of $table1count, t1c. It never returns the actual count value. I think the syntax is wrong but all of the info I've found online is 8-10 years old. Could anyone help?
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbName = "database";
$table1count = 't1c';
$table2count = 't2c';
$conn = new mysqli ($servername, $username, $password, $dbName);
if(!$conn){
die("Connection failed. ". mysqli_connect_error());
}
$sql = "SELECT ";
$sql .= "(SELECT COUNT(*) FROM table1) AS $table1count, ";
$sql .= "(SELECT COUNT(*) FROM table2) AS $table2count; ";
$result = mysqli_query($conn ,$sql);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)){
echo "table1count:" . $table1count . "|table2count:". $table2count . ";";
}
}
?>