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);
?>