I bring all users online:

$result = mysql_query("SELECT * FROM users "); while ($row = mysql_fetch_array($result)){ echo "<br>"; echo $row['username']; } 

And how now to update this list?

  • knes, do not close, nothing is clear to me from that answer, and besides my locations have no id - k0mar
  • what do you mean ? no one knows how to read your thoughts) - draev
  • O_o in the sense of? <br> If you are about updating without rebooting, then Ajax is natural ... - Zowie
  • Well, look, there are users in the location, and they need to be displayed, I display, but if they go out, you need to update the list =) - k0mar
  • you obviously do not call something in the logic .. how do you determine that users have logged in? - draev

2 answers 2

there must be fields in the Users table: 1. online - the field responds to the user in the game or not (1 in the game, 0 in the game) 2. location - a link to the location where the user was last marked.

Then a request to select all users in a specific location is such "SELECT * FROM Users WHERE online = 1 and location =". $ Location

Broadcast a function to a timer that every 5, 10, 20 minutes (as you like) sends an Ajax request to the script and displays all users of this lock.

If a user leaves the game, then update his field in the table Users online = 0. If the user has moved to another loco, update the location field for this user, and then immediately make a request for all users in this locale.

Kk so

  • All this is good =) But how do you enter a link in a location? - k0mar
  • There should be a separate table of the location list of the location: ID | NAME 1 | Mountain 2 | City, etc. And in Users.location, we set one of the values ​​of location.id - Ale_x
  • aha =) thank you =) - k0mar

The easiest way is to use jquery + ajax + setInterval (setTimeOut)

  • AND? How does ajax on the client help you understand which user is online? ^^ <br> At the TCA server, you need to write the logic first ... - Zowie
  • This is the easiest way, although not the most expedient. You need to constantly make queries to the database and find out what the user's status is - ikot
  • What to find out? What are the statuses? There was not a word about this;) - draev
  • ikot you know another? ^^ <br> Divide, we are very interested ... - Zowie
  • But it would not hurt. The answer has already given Ale_x about the status - ikot