I have a chart where I want to display numbers of users banned and activated. I want to do it as simple as using php to count numbers of rows where banned = 1
and another where both activated = 1
and banned = 0
.
Most of the solutions I've found dont work for what ever reason, some is outdated, and some I cant figure out. I use PHP7 but dont know how much thats gone change any solutions other than the oldest versions with mysqli
and mysql
1.
$result = $db->query("SELECT COUNT(*) AS banned FROM users WHERE banned = '1'");
$row = $result->fetch_assoc();
echo $row['banned']." banned users.";
$result->close();
2.
$num_banned = $db->query("SELECT COUNT(*) FROM `users` WHERE `banned` = `1`");
$row = $num_banned->fetch_row();
echo '#: ', $row[0];
$num_banned = mysqli_query($db, "SELECT * FROM users WHERE banned='1'"); $num_rows = mysqli_num_rows($num_banned);