我有一些代码,如下所示。我想帮助将其更改为普通的PHP语句,而不是面向对象。用PHP还不太好学习。
<?php
$connection=mysqli_connect("host", "username", "password", "database");
$sql="SELECT COUNT(*) from database_users";
$stmt = $connection->prepare($sql);
$stmt->execute();
$res = $stmt->get_result();
$users = $res->fetch_array(MYSQLI_ASSOC);
if ($users['COUNT(*)'] < 4) {
?>
// html goes here, outside of the php tags
<?php
} else {
echo "Sorry, you have reached the user account limit.";
};
?>
有什么想法吗?
谢谢, 查理
答案 0 :(得分:0)
试试这个你可以使用COUNT(*)
<?php
$connection=mysqli_connect("host", "username", "password", "database");
$sql="SELECT COUNT(*) as cnt from database_users";
$res = mysqli_query($connection, $sql);
$users = $result->fetch_assoc();
if ($users['cnt'] < 4) {
?>
// html goes here, outside of the php tags
<?php
} else {
echo "Sorry, you have reached the user account limit.";
}
?>