setId($style[0]); // Id of the style for use in placemarks $s->setIconId($style[1]); // Icon ID $s->setIconLink($style[2]); // Link to the icon // Add the style to the KML $kml->addItem($s); } // Get the data from the database $q = mysql_query('SELECT id,name,desc,link,city,state,country,lat,lng FROM table;'); while(list($id,$name,$desc,$folder,$lat,$lng,$style) = mysql_fetch_row($q)) { // Create a new place object $p = new XML_KML_Place; // Assign bits of the array $p->setId($id); $p->setName($name); $p->setDesc($desc); $p->setFolder($folder); $p->setStyle($style); $p->setCoords($lat,$lng); // If you have HTML in both name and desc call this //$p->setCDATA(); // If you have HTML in just desc then call this //$p->setCDATA('desc'); // Add the item to the kml $kml->addItem($p); } // Create the KML $kml->printHeader(true); // Allows the KML to be viewed in the browser //$kml->printHeader(); // Forces the user to download the KML file // Print the KML to the browser echo $kml; file_put_contents('output.kml', $kml); ?>