Players currently online
Let's build out the code to get and show a list of players that are currently online. Here we write a JavaScript function that calls our PHP module to return a list of players that are logged in.
The JavaScript function is as follows:
function GetPlayersOnlineNow(){ var action='GetPlayersOnlineNow',Username='', html="<table>"; $.ajax({ dataType: "json", data: {action:action}, url: $AJAXHANDLER, success: function (data){ for (var i = 0; i < data.length; i++) { if(data[i].UserName==''){Username='Anonymous'}else{Username=data[i].UserName}; html+='<tr><td><a href="#">'+Username +'</a></td></tr>'; } html+="</table>"; $("#playersonlinenowdiv").append(html); }, error: function (xhr, status, error) { alert(status + error + xhr.responseText); } }); }
The PHP code is as follows:
function GetPlayersOnlineNow(){ $storedProcedure = "Select UserName from Player...