Hey i'm trying to create a map for a game. I didn't know where to put this as this thread will handle HTML, CSS, JS, PHP, MYSQL and AJAX.
My experience, (just to show how much i can or can't do)
HTML and CSS : I know a lot about these languages.
PHP, MySql : I wrote the whole item database for my game, currently you can buy/sell items, put them in your backpack or stash, equip them, sort them by amount, name, type etc. this was a lot of repeating code and theres is still a lot to learn for me.
JS: i did a couple of tutorial and wrote a script to move an object around in a div.... thats pretty much it
AJAX: i just finished my first tutorial about how to work with JS, PHP and AJAX to sent and get a query from a DB.
So i started making a query to get the tiles i need to draw in an array. Then with a foreach loop i can generate divs with the corresponding options and picture.
The current problem is, the query i got here just returns the tileID of the current position. I expect the query to give me 9 values (the current tile the player is on and all the tiles next to him (a 3x3 grid)). It's probably something very simple i just can't think of atm .
$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 )
I have build my table "world" like this:
systemID -> not really used yet as there is just 1 system.
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 how to get this array data into my HTML file to load the 9 tiles into my map container with AJAX? I'm hoping to learn this today. I'm not sure if i should somehow pass this PHP array to my html file and create a JS loop that generates the tile divs in my map container div OR make the loop in PHP and put that directly into the map container div in the HTML file.