我有以下查询/输出,没有显示任何/工作。所有列表名都是正确的。我有php错误检查,它没有抛出任何错误。
这是没有输出任何内容的代码。
$total_members_query = $con->prepare("SELECT COUNT(id)FROM users WHERE `group` IN (2,3,4,5)")
or die ("Total Members query failed: %s\n".($total_members_query->error));
$total_members_query->execute();
$total_members_query->bind_result($total_members);
$numrows_members = $total_members_query->num_rows();
// $numrows_members = mysqli_num_rows($total_members_query);
if($numrows_members > 0){
while($members_row = mysqli_fetch_assoc($total_members_query)){
//$members_total = $members_row['id'];
?>
<div class="member_summary_statistics">
<div class="member_summary_category_title">League Statistics</div>
<div id="member_summary_member_count">Members in your league: <?php echo $total_members; } } ?></div>
这是更多代码。它上面和下面。
<div class="member_summary_user_birthdays">
<div class="member_summary_category_title">Today's Birthdays</div>
</div>
<?php
$total_members_query = $con->prepare("SELECT COUNT(id)FROM users WHERE `group` IN (2,3,4,5)")
or die ("Total Members query failed: %s\n".($total_members_query->error));
$total_members_query->execute();
$total_members_query->bind_result($total_members);
$numrows_members = $total_members_query->num_rows();
// $numrows_members = mysqli_num_rows($total_members_query);
if($numrows_members > 0){
while($members_row = mysqli_fetch_assoc($total_members_query)){
//$members_total = $members_row['id'];
?>
<div class="member_summary_statistics">
<div class="member_summary_category_title">League Statistics</div>
<div id="member_summary_member_count">Members in your league: <?php echo $total_members; } } ?></div>
<div id="member_summary_newest_member">Welcome our newest member - <?php echo $member_username;?>!</div>
&amp;之后的这一行中的所有内容在我的文件管理器中,符号显示为灰色而不是黑色和蓝色。
Today's Birthdays</div>
然后我的两个标题在生日文字后没有出现..
class="member_summary_category_title">League Statistics</div>
<div id="member_summary_member_count">Members in your league:
我不知道是否有任何因素影响到了正在发生的事情,因为我一遍又一遍地看着这一点并且无法解决任何问题。
我很感激任何帮助。
答案 0 :(得分:0)
您似乎在准备声明中错过COUNT(id)
和FROM
之间的空格。
编辑: 您还需要缓冲结果集,请参阅Mysqli documentation:
$total_members_query->execute();
$total_members_query->bind_result($total_members);
$total_members_query->store_result();
$numrows_members = $total_members_query->num_rows;
编辑2: 仔细看看你的陈述,我意识到你的查询将总是返回一行(因为COUNT将至少为0),为什么你可能想要采取这样的方法:
<?php
$total_members_query = $con->prepare("SELECT COUNT(id) as countId FROM users WHERE `group` IN (2,3,4,5)")
or die ("Total Members query failed: \n" . ($total_members_query->error));
$total_members_query->execute();
$total_members_query->bind_result($total_members);
$total_members_query->fetch();
if($total_members > 0){
?>
HTML-code...