使用php从mysql显示图像

时间:2018-02-09 02:59:56

标签: php html css mysql

我想显示数据库中的图像。我的图像字段的数据类型是BLOB。我在本网站的其他一些问题中使用了代码,但代码不起作用。我想在Google地图的信息窗口中显示图片。根据屏幕截图,图像标签正在显示,但图像本身不是。

[image]

我的代码:

<?php 
    require "connect.php";

    $sql = "SELECT * FROM tblLocation";
    $result = mysqli_query($conn,$sql);
    $count = mysqli_num_rows($result);

echo "<script>

        function initMap() {

            var infowindow = new google.maps.InfoWindow();

            var uluru = {lat: 14.617766, lng: 121.057154};
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 4,
              center: uluru
            });";
            if ($count > 0){
                while ($row = mysqli_fetch_array($result)) {
                    echo "var content = '<div class=".'content'.">'+
                                            '<img src=".'data:image/jpeg;base64,'.base64_encode($row['image'])."'/>'+
                                            '<p>".$row['address']."</p>'+
                                            '<span class=".'label'.">Branch:</span>'+
                                            '<span class=".'details'.">".$row['branch']."</span>'+
                                            '<span class=".'label'.">Province:</span>'+
                                            '<span class=".'details'.">".$row['province']."</span>'+
                                            '<span class=".'label'.">Phone:</span>'+
                                            '<span class=".'details'.">".$row['phone']."</span>'+
                                            '<span class=".'label'.">Latitude:</span>'+
                                            '<span class=".'details'.">".$row['lat']."</span>'+
                                            '<span class=".'label'.">Longitude:</span>'+
                                            '<span class=".'details'.">".$row['lng']."</span>'+
                                            '<button class=".'btn-edit'.">Edit</button>'+
                                            '<button class=".'btn-delete'.">Delete</button>'+
                                        '</div>';";

                                      echo  "var marker = new google.maps.Marker({
                                                content:content,
                                                position:{ lat:{$row['lat']}, lng:{$row['lng']} },
                                                map: map
                                        });

                                        marker.addListener('click', function(event) {
                                            infowindow.open( map, this );
                                            infowindow.setContent( this.content );
                                            infowindow.setPosition( event.latLng );
                                        }.bind( marker ));";

                }
            }

        echo "}
        </script>";
?>

0 个答案:

没有答案