以下代码旨在显示成员总数,但不会显示任何内容
<?php
$query = $forumdb->prepare("SELECT totalMembers FROM smf_settings");
$query->execute();
$num_rows = $query->fetch();
?>
<div class="media-body">
<p id="greet" align="left">Total Members: <?php echo .$num_rows['totalMembers']. ?> <p>
</div>
答案 0 :(得分:1)
要计算您可以使用的成员总数count
$query->execute();
$rows = $query->fetch();
$num_rows = count($rows);
或者将您的查询更改为count
并使用fetchColumn
$query = $forumdb->prepare("SELECT COUNT(totalMembers) FROM smf_settings");
$query->execute();
/* Check the number of rows that match the SELECT statement */
$num_rows=$res->fetchColumn();