$row['locX'], 'locY' => $row['locY']); } mysql_free_result($result); mysql_close(); print_r($regions); foreach($regions as $regionName => $coords) { print_r($regionName); print_r($coords); } //Width and height of each region $regionSize = 50; //Center on a coordinate $centerX = 1000; $centerY = 1000; //set X, Y upper bounds $maxX = 1005; $maxY = 1005; //set X, Y lower bounds $minX = 995; $minY = 995; //Create an image, properly sized $imageWidth = (($maxX-$minX)*$regionSize); $imageHeight = (($maxY-$minY)*$regionSize); echo $imageWidth; echo $imageHeight; $heading = ' '; //foreach region, plot square at position in image multiplied by region width foreach($regions as $regionName => $coords) { if($coords['locX'] > $minX AND $coords['locX'] < $maxX) { if($coords['locY'] > $minY AND $coords['locY'] < $maxY) { $rectangles .= ''; $text .= ''.$regionName.''; } } } $ending = ''; $stringData = $heading.$rectangles.$text.$ending; $fh = fopen('map.svg', 'w'); fwrite($fh, $stringData); fclose($fh); echo '' ?>