<?php
class HealthMap {
        public 
$count 0;
        public 
$score_scale = array(
            
'4' => array('100','97'),
            
'3' => array('96','90'),
            
'2' => array('89','80'),
            
'1' => array('79','0')
        );
    private 
$db_connection;
    private function 
db_connect() {
        
$mysqli mysqli_connect'localhost''test''test''mchd' );
        
/* check connection */
        
if (mysqli_connect_errno()) {
            
printf "Connect failed: %s\n"mysqli_connect_error () );
            exit ();
        }
        return 
$mysqli;
    }
    public function 
get() {
        
$this->db_connection $this->db_connect();
        
$sql_select_account_id "SELECT `score`, `latitude`, `longitude`, `scrape_date`
            FROM inspections i
            INNER JOIN establishment_geo_data g
            ON i.mchd_id = g.mchd_id
            WHERE score > 0
            ORDER BY `score` DESC"
;
        
$result $this->db_connection->query($sql_select_account_id);
        
$output "";
                
$count 0;
                while(
$row mysqli_fetch_array($resultMYSQLI_ASSOC)) {
                        
$this->count++;
            
$scale_color '';
                        foreach (
$this->score_scale as $color_hex => $range) {
                            if(
$row['score']<=$range[0]&&$row['score']>=$range[1]) {
                                
$scale_color $color_hex;
                                break;
                            }
                        }
                        
$output .= "map.addOverlay(new GMarker(new GLatLng({$row['latitude']}, {$row['longitude']}),{icon:icons[{$scale_color}],zIndexProcess:orderOfCreation}));";
                        
$count++;
        }

        
$result->close();
        return 
$output;
    }
}
?>
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=** YOUR GOOGLE KEY HERE **" type="text/javascript"></script>
    <script type="text/javascript">
    function orderOfCreation(marker,b) {
      return 1;
    }

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(45.5165100098,-122.678878784), 13);
        map.setUIToDefault();
        //map.addOverlay(new GMarker(new google.maps.LatLng(45.52269500000, -122.63536500000)));
    var icons=[];
      for (index=4;index>=1;index--) {
            icons[index] = new GIcon();
            icons[index].image = "icons/"+index+".png";
            icons[index].shadow=null;
            icons[index].iconSize=new GSize(8,8);
            icons[index].shadowSize=new GSize(0,0);
            icons[index].iconAnchor=new GPoint(3,3);
          }

        <?php
        $healthMap 
= new HealthMap();
                echo 
$healthMap->get();
        
?>
      }
    }

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 600px; height: 600px; float:left;"></div>
    <div style="float:left;">
    <div>Plotted:<span id="points"><?php echo($healthMap->count); ?></span> points</div>
    <ul>
        <li style="background-color:#19E100;width:10em;">100 --&gt; 97</li>
        <li style="background-color:#4BAF00;width:10em;">96 --&gt; 90</li>
        <li style="background-color:#E88746;width:10em;">89 --&gt; 80</li>
        <li style="background-color:#DF4400;width:10em;">79 --&gt; 0</li>
    </ul>
    </div>
  </body>
</html>