Plotting mysql values in a dynamic image.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noctiluca
    New Member
    • Oct 2006
    • 2

    Plotting mysql values in a dynamic image.

    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 = imagecreatefrom png ("mapsize.png") ;
    $red = imagecoloralloc ate($image, 255,0,0);

    //Connect to mysql
    INCLUDE("xxxx.p hp");

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

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

    while ($row = mysql_fetch_arr ay($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
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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:

    Comment

    • Noctiluca
      New Member
      • Oct 2006
      • 2

      #3
      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!

      Comment

      Working...