不回显结果,我认为因为结果是总和而不是db中的特定条目?
<?PHP
error_reporting('E_ALL');
include('session.php');
include('config.php');
$sql="SELECT SUM(grading) FROM (SELECT * FROM 'trails' WHERE `name` = 'Free Flow' ORDER BY `id` DESC LIMIT 5) AS DATA";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $row['grading'];
}
?>
更新版本给出了lank page ...
<?PHP
error_reporting(E_ALL);
include('session.php');
include('config.php');
$sql="SELECT SUM(grading) AS grading FROM (SELECT * FROM `trails` WHERE `name` = "Free Flow" ORDER BY `id` DESC LIMIT 5) AS DATA";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)) {
echo $row['grading'];
}
?>
答案 0 :(得分:1)
标识符可以以数字开头,但除非引用可能不仅仅由数字组成。
数据库,表和列名称不能以空格字符结尾。
数据库和表名称不能包含“/”,“\”,“。”或文件名中不允许的字符。
标识符引号字符是反引号(“`”):
在FROM之后删除撇号(我的意思是FROM 'trails'
)并用反引号替换“`”。
您的SQL查询将如下所示:
$sql="SELECT SUM(`grading`) as `grading`
FROM (SELECT * FROM `trails` WHERE `name` = 'Free Flow'
ORDER BY `id` DESC LIMIT 5) AS DATA";
答案 1 :(得分:0)
确保连接成功连接,SQL查询正确,数据库表有条目,并且您使用正确的列名称打印,如$ row [&#39;评分&#39;]。
答案 2 :(得分:0)
问题来自:
error_reporting('E_ALL');
'E_ALL'不是常量,它是一个字符串。 PHP将静默地将其强制转换为int,并使其成为错误报告的配置值。
(int) 'E_ALL' == 0
error_reporting(0)隐藏所有错误,这就是你得到空白页面的原因。
答案 3 :(得分:0)
您必须为SUM创建索引,所以:
SELECT SUM(grading) AS sum_grading FROM (SELECT * FROM trails WHERE `name` = 'Free Flow' ORDER BY `id` DESC LIMIT 5) AS DATA
然后:
echo $row['sum_grading']