Properly building array and using with drupal_json_encode()? I am trying to pass data from my database to a javascript variable, however I'm not sure if I'm correctly using drupal_json_encode(), or correctly building my 2D array.

When I check my console, the javascript variable only displays [], so the data is not being passed.

I know this isn't the very best way of doing this, but I am only trying to make a functioning prototype, and not a finished product

Here is a portion of my php code that is making the sql query, as well as the 2D array, and is located in my page--front.tpl.php:

&lt;?php
$server = 'db.*****';$user = '*****';$database = '*****';$password = '*****';
$db = mysqli_connect($server, $user, $password, $database);

  if (isset($_GET['routeselected'])) 
  {
  $result = mysqli_query($db, "SELECT * FROM STOP INNER JOIN RouteStop ON Stop.Stop_ID = RouteStop.Stop_ID WHERE RouteStop.Route_ID = " . (int)$_GET['routeselected'] . " AND RouteStop.Company_ID = " . (int)$_GET['companyselected']);
  $items = array();
  while (($row = mysqli_fetch_array($result))){
      $markers[$row['title']] = array($row['Stop_ID']);
      $markers[$row['lat']] = array($row['Latitude']);
      $markers[$row['lng']] = array($row['Longitude']);
      $markers[$row['description']] = array($row['StopName']);
      }
    drupal_json_encode($markers);
    drupal_add_js(array('markers' =&gt; drupal_json_encode($markers)), 'setting');
  }
  ?&gt;
];


and here is my google map javascript that is in my js folder and is being implemented to the front page via drupal_add_js:

var map = null;
var infowindow = new google.maps.InfoWindow();
var markers = [Drupal.settings.markers];

window.onload = function () {

var mapOptions = {
    center: new google.maps.LatLng(
        parseFloat(markers[0].lat),
        parseFloat(markers[0].lng)),
    zoom: 13,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var path = new google.maps.MVCArray();
var service = new google.maps.DirectionsService();
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var poly = new google.maps.Polyline({map: map, strokeColor: '#F3443C'});

var lat_lng = new Array();
           for (i = 0; i &lt; markers.length; i++) {
           var data = markers[i]
           var myLatlng = new google.maps.LatLng(data.lat, data.lng);
           lat_lng.push(myLatlng);
           var marker = new google.maps.Marker({
               position: myLatlng,
               map: map,
               title: data.title
           });
           (function (marker, data) {
               google.maps.event.addListener(marker, "click", function (e) {
                   infoWindow.setContent(data.description);
                   infoWindow.open(map, marker);
               });
           })(marker, data);
       }
for (var i = 0; i &lt; markers.length; i++) {
    if ((i + 1) &lt; markers.length) {
        var src = new google.maps.LatLng(parseFloat(markers[i].lat), 
                                         parseFloat(markers[i].lng));
        var des = new google.maps.LatLng(parseFloat(markers[i+1].lat), 
                                         parseFloat(markers[i+1].lng));
        service.route({
            origin: src,
            destination: des,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        }, function (result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                for (var i = 0, len = result.routes[0].overview_path.length; i &lt; len; i++) {
                    path.push(result.routes[0].overview_path[i]);
                }
                poly.setPath(path);
            }
        });
    }
}
} 


Does anyone possibly know a solution to my issue? Thank you for all and any help!
drupal_add_js(array('markers' =&gt; drupal_json_encode($markers)), 'setting');

Should be 

drupal_add_js(array('markers' =&gt; $markers), 'setting');

See https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_js/7. You will probably want to remove the drupal_json_encode($markers); as well.

Also noted that you should use db_query instead of mysqli_connect/mysqli_query https://stackoverflow.com/questions/11369447/drupal-7-db-query