Admiral S3 Posted November 19, 2009 Share Posted November 19, 2009 Hello all: Let me give you some background, over the past 10 years I have dealt with many forums, and even built some limited PHP scripts myself for various things related to those forums. Usually modifications to expand the forums abilities. So I had thought I had a fairly good handle on PHP in general... LOL, that is until recently when I decided to take on a slightly different/larger challenge. Recently one of my forum users requested the creation of a X,Y Coordinate grid, where they could put into it certain bits of information and it would return showing them the X,Y location of thier various work attached in some way shape or form to his site. I had thought this would be a simple project, as I have worked with GD image creation before, as well as SQL statements many times, it simply should have been a blending of my exsisting knowledge into one program. While this was a unique challenge for me, its one I seem to have been unable to plug. I have searched the web extensively the last 2 weeks hoping to find a tutorial, and sadly while I can find a great many related to bar graphs and line graphs, I can't seem to find a single one related to a simple X Y coordinate graph, yet I know I have seen them done many times. I am at a total loss on this one and so far my attempts have garnered me 0 results. I can't even create a 20 x 20 grid with any success... LOL. I am hoping one of you would be kind enough to post a tutorial, with a simple code that would produce a grid using GD, or even some other form of image generation, with 1 - X Y plot in it generated either from SQL or from the program its self, so that I could see a working version and with luck go from there to expand it to my needs. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/ Share on other sites More sharing options...
j0n Posted November 19, 2009 Share Posted November 19, 2009 May I recommend jpGraph: http://www.aditus.nu/jpgraph/ Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-961240 Share on other sites More sharing options...
Admiral S3 Posted November 20, 2009 Author Share Posted November 20, 2009 Err well.... not quite what I had in mind, I would of course rather learn that which I am missing then have a program do it for me. So while I thank you for your input I will hold out a bit and see if someone has a base line code I can start from, learn and then expand from there on. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-961752 Share on other sites More sharing options...
Admiral S3 Posted November 20, 2009 Author Share Posted November 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-961779 Share on other sites More sharing options...
Admiral S3 Posted November 22, 2009 Author Share Posted November 22, 2009 I am gonna guess this one even stumps the experts? Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-963176 Share on other sites More sharing options...
Daniel0 Posted November 22, 2009 Share Posted November 22, 2009 I'm not really sure what you want the output to be. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-963180 Share on other sites More sharing options...
ubersmuck Posted November 25, 2009 Share Posted November 25, 2009 Try placing the following code at the end of your script: $docroot = $_SERVER['DOCUMENT_ROOT']; imagepng($im, $docroot.'/map.png'); imagedestroy($im); Your code will still display errors but the image will be outputted to your files location. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-965340 Share on other sites More sharing options...
Admiral S3 Posted December 19, 2009 Author Share Posted December 19, 2009 ubersmuck: Thank you... thats at least very close to what I want. I can write a code string to get that to show up at the very least. Daniel0: What I am attempting to do, is to have PHP produce a 2D X, Y coordinate grid appear complete with data from SQL, or MySQL. Basically think of it as a map, as that what it is from what I understand for a game one of my customers plays. Basically showing where his friends are, and where his enemies are. PHP may not exactly be the best way to represent this, but its what I know to a fair degree. LOL However if anyone has any alternative code strings that could be of use I am always willing to expand my knowledge. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-980470 Share on other sites More sharing options...
Admiral S3 Posted December 19, 2009 Author Share Posted December 19, 2009 http://simplysimonhosting.com/map.png In case anyone wanted to know exactly what I am looking for. The above is so far the best that can be generated. Essentially the red dot represents a person in this game. Ultimatly it would great to have some mouse over details when a person moves thier mouse over the dot to show what that persons status is, and what they are, IE friend, or foe. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-980471 Share on other sites More sharing options...
sandbird Posted January 24, 2012 Share Posted January 24, 2012 Exactly what i am looking for also...has anyone figured this out ? Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-1310708 Share on other sites More sharing options...
premiso Posted January 24, 2012 Share Posted January 24, 2012 Exactly what i am looking for also...has anyone figured this out ? Don't necro a dead topic (over 2 years old). Create your own topic, feel free to link to it stating you have a similar problem, but yea. Quote Link to comment https://forums.phpfreaks.com/topic/182134-x-y-coordinate-grid-using-php-with-data-in-sql/#findComment-1310722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.