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)
How to find players at X, Y position?
How to find players at X, Y position?
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Re: How to find players at X, Y position?
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.
Fighting for peace is declaring war on war. If you want peace be peaceful.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: How to find players at X, Y position?
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!
The indelible lord of tl;dr
Re: How to find players at X, Y position?
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
The while code is the way the best way to go through them all? Or is there a better method than that?
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
}Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Re: How to find players at X, Y position?
Oh, kind of related to this
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
Code: Select all
$locationwholeentry= $locationinfo3['location1'];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
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog