PHP / MySQL无法打印查询生成的列

时间:2016-05-28 13:16:01

标签: php mysql

我正在尝试基于一个名为UID的字段构建“前15名”结果,除了不在PHP中打印count列之外,效果很好,但它在PHPMyAdmin中也是如此。

function buildHtml(channels, ready) {
    // Use an array, so you can store each response in the corresponding slot
    var html = [];
    // Keep a count of the replies you still need
    var count = channels.length;
    $.each(channels,function(index, value){
        // for elements that are links
        if(value.substring(0,4)=="http"){
            $.getJSON(value,function(json){
                html[index] = json.name;
                count--;
                if (count == 0) {
                    // All is done, notify the caller:
                    if (ready) ready(html.join(''));
                }
          });
        }
           // for elements that are not links
        else {
            html[index] = value;
            count--;
        }
    });
    if (count == 0) { // Only true if there were no http entries:
        // All is done, notify the caller:
        if (ready) ready(html.join(''));
    }
}

channels=["https://link1","https://link2","name(for closed account)",....];
// Provide a call back function that is called when html is complete:
buildHtml(channels, function (html) {
    console.log('The returned HTML is: ' + html);
});

这是返回数组:

SELECT * , COUNT( UID ) AS Count
FROM UserReports
GROUP BY  `UID` 
ORDER BY Count DESC 
LIMIT 15

PHP代码:

( [ID] => 18 [Date] => 2016-05-28 13:58:05 [Name] => a [UID] => a [Reason] => a [Staff] => Patrick [Count] => 2 ) 

( [ID] => 19 [Date] => 2016-05-28 13:58:07 [Name] => b [UID] => b [Reason] => b [Staff] => Patrick [Count] => 1 ) 

但输出没有为我显示计数列,我无法理解为什么。

Missing Column

提前致谢。

2 个答案:

答案 0 :(得分:1)

回答评论,看到这是真正的问题。

屏幕截图中有6列,但循环中只有5 <td>个。看看你自己的截图;你有2个和1个计数。看看你的HTML源代码;它也是一个&#34;工具&#34;。

这里发生的是迭代值已经移位。

您需要匹配它们。

答案 1 :(得分:0)

请勿将select *group by一起使用。这是MySQL中的(错误)功能,既不受标准也不受其他数据库的支持。

相反,请关注感兴趣的列:

SELECT UID, COUNT( UID ) AS Count
FROM UserReports
GROUP BY  `UID` 
ORDER BY Count DESC 
LIMIT 15;

如果您想要其他列,例如NAME,请将它们包装在聚合函数(MAX(NAME))中,或将它们包含在GROUP BY中。