drawing points from mysql with php/mapscript

Mark Brooks mark_brooks at NCSU.EDU
Mon Dec 5 11:37:43 EST 2005


I'm trying to draw points from a MySQL database onto a map with 
PHP/Mapscript.  I found no clear examples online and so far have had 
little luck at being successful.  Does anyone out there have any 
examples you could share?

Here is part of my mapfile, which sets up an empty layer for the sites I 
want to draw on the map....
LAYER
	NAME sites
	TYPE POINT
	STATUS DEFAULT
	CLASS
	   NAME 'Project Sites'
	   COLOR 150 150 150
	   SYMBOL 'circle'
	   SIZE 10
	   LABEL
	      TYPE truetype
	      FONT "arial"
	      SIZE 10
	      POSITION UC
	      COLOR 150 150 150
	   END
	END
END


And a watered-down snippet from my php code to draw the dynamic points 
from mysql:

$image = $map->draw();
$this_layer = $map->getLayerByName('sites');
$this_layer->set('status', MS_ON);
//query database for points
$query = "select bla bla";
$sresult = mysql_query($query);
// loop through database results, adding the new point to the layer
while ($site = mysql_fetch_assoc($sresult)){
	$mypoint = ms_newPointObj();
	$mypoint->setXY($site['lat'],$site['lon']);
	$mypoint->draw($map,$this_layer,$image,0,$site['name']);		}


My site points are latitude,longitude.  When I do all this, I only get 
ONE point drawn on my map.  There are dozens of points but only one gets 
plotted, and I'm not entirely certain that it truly is a point from my 
database.  I even hardcoded several different coordinates but only one 
dot appears on my map.

What am I missing?


-- 

   Mark Brooks
   Meteorologist
   State Climate Office of North Carolina
   Box 7236, NC State University
   Raleigh, NC 27695-7236

   E-mail:  mark_brooks at ncsu.edu
   Phone:  919.515.1446
   Fax:  919.515.1441



More information about the mapserver-users mailing list