Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Im guessing that you need to iterate between the results and then echo them into the javascript.</p> <p>Im assuming you have the lat and lng stored in your database.</p> <pre><code>$coordinates = array(); $result = dbMySql::Exec('SELECT lat, lng FROM table WHERE id = 1'); while ($row = mysqli_fetch_assoc($result)) $coordinates[] = 'new google.maps.LatLng(' . $row['lat'] . ', ' . $row['lng'] . ')'; </code></pre> <p>And then on your javascript section</p> <pre><code>var flightPlanCoordinates = [ &lt;?php echo implode(',', $coordinates) ?&gt; ]; </code></pre> <p>Edit:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;?PHP class dbMySql { static function Exec($query) { // open database $conn = mysqli_connect('localhost','root','*****'); if($conn === false) { throw new Exception(mysqli_connect_error()); } mysqli_select_db($conn,'data_gps'); $result = mysqli_query($conn,$query); if(is_bool($result) &amp;&amp; !$result) { $error = mysqli_error($conn); mysqli_close($conn); throw new Exception($error); } //mysqli_close($conn); return $result; } } $coordinates = array(); $result = dbMySql::Exec('SELECT lat,lng FROM data'); while ($row = mysqli_fetch_assoc($result)) $coordinates[] = 'new google.maps.LatLng(' . $row['lat'] . ', ' . $row['lng'] . ')'; ?&gt; &lt;html&gt; &lt;head&gt; &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt; &lt;style type="text/css"&gt; html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } &lt;/style&gt; &lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=key&amp;sensor=true"&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; function initialize() { var myLatLng = new google.maps.LatLng(0, 180); var myOptions = { zoom: 3, center: myLatLng, mapTypeId: google.maps.MapTypeId.TERRAIN }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var flightPlanCoordinates = [&lt;?php echo implode(',', $coordinates) ?&gt;]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 }); flightPath.setMap(map); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="initialize()"&gt; &lt;div id="map_canvas" style="width:100%; height:80%"&gt;&lt;/div&gt; &lt;div&gt;&lt;button type="button"&gt;Click Me!&lt;/button&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload