May 30th, 2010, 02:48 PM
[MySql] range query
I want to make a world map for a game but before i (can) do that i need to learn how to and what the possibilities are. Therefor i am building a test environment. But i'm already kinda stuck on my first query.
I have made this table called "world" with these columns:
systemID -> not really used yet as there is just 1 system/world.
orderID -> dunno if i really need this one as i could probably order my table from the xpos and ypos.
tileID -> refers to the primary key of the table where i store my tiles.
I have filled this table with 25 rows to represent a 5x5 grid. where all the outer tiles are 3 (water) the middle tile (3,3) is 2 (desert) and the rest are 1 (grass).
Now my query needs to select all the "tiles" around the players location. Unfortunately my query only returns the current position to me where i expect it should give me 9 values. Here's the code:
$xpos = 3; //this variable should get feeded by a $_GET or $_POST or something.
$ypos = 3; //this variable should get feeded by a $_GET or $_POST or something.
$mapquery = mysql_query ("
(xpos BETWEEN '$xpos - 1' AND '$xpos + 1')
(ypos BETWEEN '$ypos - 1' AND '$ypos + 1')
") or die (mysql_error());
$mapgen = mysql_fetch_assoc($mapquery);
print_r ($mapgen); //this only gives me the tile i'm currently on -> Array ( [tileID] => 2 )
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.