By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

Plotting mysql values in a dynamic image.

P: 2
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);
?>
Oct 2 '06 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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:
Oct 2 '06 #2

P: 2
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!
Oct 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.