LOL, alright perhaps I will have a touch better luck with this route.
Desired effect: List locations of all persons in the database, in this case enemies only.
This is an example of the code, obviously SQL connections are disabled, and as this is the test grid, the size is significantly smaller then the desired size.
MYSQL databse contains one entry with the following data.
lord_num, (auto inc) 1
lord_name, varchar (16), Admiral S3
alliance, varchar (40), {no data entered.}
x, decimal (5,0), 40
y, decimal (5,0), 40
type, varchar (20), Member (this is reserved for later versions of this grid, eventually this will allow users to select "show members", "show allies", "Show Enemies", "show neutrals".)
THE CODE:
<?php
// set the HTTP header type to PNG
header("Content-type: image/png");
mysql_connect("localhost", "username", "password") or die("Mysql Error");mysql_select_db("database") or die("Database error.");
// Image Size
$height = 618;
$width = 618;
$im = ImageCreate($width, $height);
// this is the image
// Colors
$grass = ImageColorAllocate($im, 67,154,67);
$enemy = ImageColorAllocate($im, 255,0,0);
$bgcolor = ImageColorAllocate($im, 39,104,39);
ImageFill($im, 0, 0, $bgcolor);
// Fill the image with the background color
$size = 5;
// size of a block, 5 x 5
$size2 = $size + 1;
// don't change this, it is for spacing
$query = "SELECT * FROM `mapdata`";
// get all user information
$result = mysql_query($query);
$userarray;
// initialize variable
while($row = mysql_fetch_array($result))
{
$userarray[$row['x'] . ',' . $row['y']] = true;
// load all the user info we need into an array
}
for($b=0; $b<=100; $b++)
// the grid is 100 x 100, this will make the Y columns
{
for($i=0; $i<=100; $i++)
// the grid is 100 x 100, this will make the X rows
{
if ($userarray[$i . ',' . $b] == true)
// If the $userarray says that there is somebody in this location
{
ImageFilledRectangle($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $enemy);
}
else
{
// Nobody lives there, draw some grass.
ImageFilledRectangle($im, 1+$i*$size2, 1+$b*$size2, $size+$i*$size2, $size+$b*$size2, $grass);
}
}
}
?>
Current Output results in a single white square. So does anyone have any idea why this code is not generating the results desired, and if so... is willing to show me where the error is and in some detail explain to me why its not working as expected. This way I can learn where the problem lies and why the problem exsists at all.
Thank you.