Page 1 of 1
How to find players at X, Y position?
Posted: Sun Nov 07, 2010 9:05 am
by Callan S.
Like, say a players entry in the database has an X and Y entry. How do I find all players that are at a particular X,Y position? The only method I know of is to use a while loop that ends once the database returns nothing and some sort of 'SELECT * FROM players WHERE x=whatever and y=whatever limit 1' call to the database.
Is that pretty much the best way? I'd like to show the names of other players that are standing around in a particular map location (like urban dead does)
Re: How to find players at X, Y position?
Posted: Sun Nov 07, 2010 1:04 pm
by Chris
What I'd recommend is you use open phpMyAdmin, select you table. And click the search tab at the top. There you'll get a list of options and ways to search through what you need. And once you have got what you want, use the query phpMyAdmin provides.
Re: How to find players at X, Y position?
Posted: Sun Nov 07, 2010 2:49 pm
by Jackolantern
Wow, I actually never knew that! I always figured "What is the use of a search option in phpMyAdmin?", but that actually sounds very useful!
Re: How to find players at X, Y position?
Posted: Sun Nov 07, 2010 10:34 pm
by Callan S.
Cool tip, Chris! Thanks! But in terms of finding all the players at X,Y, basically it comes down to using a while script that keeps going until the DB call comes up a blank? Kinda like this, which I got the guts of from a highscore generator I found somewhere
Code: Select all
$playerinfo = "SELECT name, FROM players WHERE x='$xtocheck' AND y='$ytocheck'";
$playerinfo2 = mysql_query($playerinfo);
while($playerinfo3 = mysql_fetch_array($playerinfo2))
{
etc
}
The while code is the way the best way to go through them all? Or is there a better method than that?
Re: How to find players at X, Y position?
Posted: Wed Nov 10, 2010 2:42 am
by Callan S.
Oh, kind of related to this
Code: Select all
$locationwholeentry= $locationinfo3['location1'];
I'm going to have location1, location2, location3 etc in the database, representing the locations for the X dimension of a map.
In my code, is there a way to refer to location1 without typing one and using a variable there? So I have a nice elegant for loop when I'm drawing the database into RAM?
Edit: Oh wait, I figured it - just need to assemble a string with it all in it and just use that. Thanks anyway
