我使用从php中的mysql数据库获取的数据在web应用程序中创建了一个排行榜。网页还有其他功能以及其他sql查询。排行榜的参考是
what is the best practice leaderboard with php, mysql, memcached?,
让我担心的问题是有更好的方法来考虑 制作排行榜应用程序?
与此同时,我遇到了Firebase,并且能够在Fiddle中运行代码,如下所示:
var LEADERBOARD_SIZE = 6;
var scoreListRef = new Firebase('https://i62qrqslypp.firebaseio-demo.com//scoreList');
var htmlForPath = {};
function handleScoreAdded(scoreSnapshot, prevScoreName) {
var newScoreRow = $("<tr/>");
newScoreRow.append($("<td/>").append($("<em/>").text(scoreSnapshot.val().name)));
newScoreRow.append($("<td/>").text(scoreSnapshot.val().score));
htmlForPath[scoreSnapshot.key()] = newScoreRow;
// Insert the new score in the appropriate place in the table.
if (prevScoreName === null) {
$("#leaderboardTable").append(newScoreRow);
}
else {
var lowerScoreRow = htmlForPath[prevScoreName];
lowerScoreRow.before(newScoreRow);
}
}
function handleScoreRemoved(scoreSnapshot) {
var removedScoreRow = htmlForPath[scoreSnapshot.key()];
removedScoreRow.remove();
delete htmlForPath[scoreSnapshot.key()];
}
var scoreListView = scoreListRef.limitToLast(LEADERBOARD_SIZE);
scoreListView.on('child_added', function (newScoreSnapshot, prevScoreName) {
handleScoreAdded(newScoreSnapshot, prevScoreName);
});
scoreListView.on('child_removed', function (oldScoreSnapshot) {
handleScoreRemoved(oldScoreSnapshot);
});
var changedCallback = function (scoreSnapshot, prevScoreName) {
handleScoreRemoved(scoreSnapshot);
handleScoreAdded(scoreSnapshot, prevScoreName);
};
scoreListView.on('child_moved', changedCallback);
scoreListView.on('child_changed', changedCallback);
$("#scoreInput").keypress(function (e) {
if (e.keyCode == 13) {
var newScore = Number($("#scoreInput").val());
var name = $("#nameInput").val();
$("#scoreInput").val("");
if (name.length === 0)
return;
var userScoreRef = scoreListRef.child(name);
userScoreRef.setWithPriority({ name:name, score:newScore }, newScore);
}
});
输出排行榜:
我也是Firebase的新手,请指导我解决问题