Connecting Tech Pros Worldwide Help | Site Map

Plotting mysql values in a dynamic image.

Newbie
 
Join Date: Oct 2006
Posts: 2
#1: Oct 2 '06
Hi folks,
Very much a learner when it comes to programming so excuse me if this is a silly question...
I'm trying to generate a map of the positions of moth records in a mysql database using PHP dynamic images.
I have managed to plot points by hand coding coordinates, however when I try to include an sql query to get coordinates, the image will not generate. I have tested the sql query on its own and it generates the appropriate output. If I simply embed the query into the code, but do not use the output of the query instead using inputted values the image does not generate. I can only assume that the query is causing a problem, but cannot find why.
Any advice would be much appreciated (code below)
Chris

<?php
header("Content-type: image/gif");
$image = imagecreatefrompng ("mapsize.png");
$red = imagecolorallocate($image, 255,0,0);

//Connect to mysql
INCLUDE("xxxx.php");

//Select gridrefs from dbase
$sql = "SELECT Gridref FROM moths2 WHERE Code=343";

$cursor = mysql_query($sql); if (!$cursor) { echo("<h3>SQL error: "
. mysql_error() ."<h3>"); exit(); }

while ($row = mysql_fetch_array($cursor) ) {

//Determine the number of coordinates in Grid ref, will sort out prefix later.
$aggri=$row["Gridref"];
$aggri1=strlen($aggri);

//if of form xx##
if ($aggri1=="4") { $xgrid=$aggri[3]; $ygrid=$aggri[4]; }
//if of form xx####
if ($aggri1=="6") { $xgrid=$aggri[3]*10; $ygrid=$aggri[5]*10; }
//if of form xx######
if ($aggri1=="8") { $xgrid=$aggri[3]; $ygrid=$aggri[6]; }
//if of form xx########
if ($aggri1=="10") { $xgrid=$aggri[3]; $ygrid=$aggri[7]; }

//Use positions to plot points on basemap
imagearc( $image, $xgrid,$ygrid, 5, 5, 0, 360, $red);
imagefill( $image, $xgrid,$ygrid, $red);

}
mysql_close( $dbh );
imagegif($image);
?>
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Oct 2 '06

re: Plotting mysql values in a dynamic image.


Do a print_r($row) for each row right after the while and you'll see the data from your table. (if there are backslahes in it, assign the $aggri value using the stripslashes() command.). When you are then sure the data is correctly read from the db, you can inspect your handling code

Ronald :cool:
Newbie
 
Join Date: Oct 2006
Posts: 2
#3: Oct 2 '06

re: Plotting mysql values in a dynamic image.


Thanks. It turned out to be the include call, which set the page to return as text conflicting with the call to create an image which thought it was producing a graphic.
Cheers!
Closed Thread