在我的页面上,我通过PHP PDO从SQL数据库中获取了一堆信息。
$query=$pdo->prepare("SELECT `balance`,`followers`,`following` FROM `users` WHERE `username`=?");
$query->bindValue(1,$logged);
$query->execute();
$followerslist=$query->fetch();
$userbalance=$followerslist['balance'];
?>
<div class="span4">
<h3>
<?=$userbalance;?>
</h3>
</div>
上面没有显示任何内容。一片空白。然而,当我删除<h3>
标签时,它就起作用了!如果I echo $userbalance;
在<h3>
块之外,它也可以工作。如果我将$userbalance
更改为等于一些随机文本,而不是SQL表中的数据集,则它在<h3>
块内工作。出于某种原因,它拒绝显示来自我的SQL表的信息。
然而,每当我在同一个<h3>
块内echo
"追随者"answers"追随者"时,它就会起作用。需要明确的是,"平衡"是一个数值。
发现问题!
在"bootstrap.css"中有一行代码叫做"textrendering:optimizelegibility;"。一旦我禁用了它,一切都恢复了正常。感谢大家的帮助!
Leandro Oliva关于打开标签的观点是正确的。您提供的代码片段缺少<?php
打开标记。为了进行进一步的调试,我建议打开error_reporting。你可能知道这一点,但这是函数error_reporting(E_ALL)
中内置的php。更多详细信息可以在这里找到。
我指的是查询字符串。这是你的代码
$query=$pdo->prepare("SELECT `balance`,`followers`,`following` FROM `users` WHERE `username`=?");
$query->bindValue(1,$logged);
$query->execute();
$followerslist=$query->fetch();
$userbalance=$followerslist['balance'];
?>
以下是具有适当的打开标记的代码应该是什么样子的。
<?php
//shorthand opening tag should work as well
//if this is the second line of php script
//place error reporting function before any script begins but after php opening tag
error_reporting(E_ALL);
$query=$pdo->prepare("SELECT `balance`,`followers`,`following` FROM `users` WHERE `username`=?");
$query->bindValue(1,$logged);
$query->execute();
$followerslist=$query->fetch();
$userbalance=$followerslist['balance'];
?>
我认为username应该等于一个字符串。你有"username"=?
,应该是"username"="bob"
。