title: Use data from database to call an Image and use it as marker image in leaflet
body: <p>Good Day, I just wanna ask something about markers.<br>
  1. I have a folder consist of 3 gif's and that is fire,carnapping and homicide<br>
  2.I also have a database,a table and inside of that I have a field name "icon_name" with other fields 3. This is my image folder location <code>C:\wamp\www\wew\legends</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code>      function getInfo() { 
    $.getJSON("get_info.php", function (data) { 
      for (var i = 0; i &lt; data.length; i++) { 
        var location = new L.LatLng(data[i].lat, data[i].lng); 
        var marker = new L.Marker(location,{iconUrl: 'C:\wamp\www\New System CS\SanBartolome\wew\legends' + data[i].icon_name + '.gif'}); 
         marker.bindPopup(
            data[i].name + "&lt;br&gt;" + 
            data[i].user_date + "&lt;br&gt;" + 
            data[i].user_time + "&lt;br&gt;" + 
            data[i].address + "&lt;br&gt;"
         ).addTo(map);
         marker.on('click', function(e) { // HERE YOU GO
            var ll = marker.getLatLng();
            document.querySelector('#userLat1').value = ll.lat;
            document.querySelector('#userLng1').value = ll.lng;
            alert('You have selected a Marker that will be deleted');
         });
       } 
    });
  }
  </code></pre>
  
  <p>Here is the <code>get_info.php</code></p>
  
  <pre><code>&lt;?php 
  $db = new PDO('mysql:host=localhost;dbname=poi', 'root', ''); 
  $sql = "SELECT name,user_date,user_time,address,lat,lng,icon_name FROM tblmarker"; 
  
  $rs = $db-&gt;query($sql); 
  if (!$rs) { 
      echo "An SQL error occured.\n"; 
      exit; 
  } 
  
  $rows = array(); 
  while($r = $rs-&gt;fetch(PDO::FETCH_ASSOC)) { 
      $rows[] = $r; 
      $name[] = $r['name'];
      $user_date[] = $r['user_date'];
      $user_time[] = $r['user_time'];
      $address[] = $r['address'];
      $icon_name[] = $r['icon_name'];
  } 
  print json_encode($rows); 
  $db = NULL; 
  ?&gt; 
  </code></pre>
  
  <p>This is what it does:  </p>
  
  <p>1.call my <code>get_info.php</code> which consist of a code of <code>select * from tablename</code><br>
  2.var location: get the value of lat and long in database<br>
  3.creating the marker (default marker)<br>
  4. get the data from database and transfer it in leaflet bindpop up</p>
  
  <p>and the result is a default marker in a map that has been generated using the data from database.</p>
  
  <p>This is my question: How can I pass the data inside my table field "icon_name" into the markers image? I mean use the icon_name data's to call the image in a folder and use it as a marker.</p>
  
  <p>TYIA</p>