无法使用PHP打印MySQL查询的结果

时间:2012-10-08 21:36:57

标签: php mysql echo

我有以下MySQL查询

$jokerQuery = mysql_query("SELECT `Joker sport`,
        COUNT(`Joker sport`) AS jokerCount
        FROM Profiles
        WHERE `CompetitorID` = 5
        GROUP BY `Joker sport`
        ORDER BY COUNT(`Joker sport`) DESC
        LIMIT 1
    ");

在phpMyAdmin中返回以下结果

Joker sport | jokerCount
8           | 8

我认为以下php会显示结果,但它不起作用。我应该写什么来回应结果?

$jokerResult = mysql_fetch_array($jokerQuery);
echo $jokerResult['Joker sport'];
echo $jokerResult['jokerCount'];

2 个答案:

答案 0 :(得分:1)

试试这个,在mysql_fetch_array中添加MYSQL_ASSOC作为const:

$jokerResult = mysql_fetch_array($jokerQuery, MYSQL_ASSOC);
echo $jokerResult['Joker sport'];
echo $jokerResult['jokerCount'];

答案 1 :(得分:1)

您也可以尝试:

$jokerResult = mysql_fetch_array($jokerQuery, MYSQL_ASSOC);
print_r($jokerResult);

查看列名。