1
我真的不知道到底我錯了圖像。可能很簡單,但我無法弄清楚。任何幫助將是偉大的,請和謝謝。檢索JSON文件,該文件是在數據庫和顯示HTML img標籤
JSON代碼(它被存儲在 '圖像' 列在數據庫tblproducts表)
{"200x200":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-200x200-imaezt6hypjzhdug.jpeg","400x400":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-400x400-imaezt6hypjzhdug.jpeg","800x800":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-800x800-imaezt6hypjzhdug.jpeg","unknown":"http://img.fkcdn.com/image/mobile/p/s/u/lenovo-k6-power-k33a42-original-imaezt6hypjzhdug.jpeg"}
HTML & PHP代碼:
<?php
$category_id = $_GET['category_id'];
$result = mysql_query("select * from tblproducts where category_id = '$category_id");
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
?>
<script>
var data =
data.forEach(function(obj) {
var img = new Image();
img.src = obj.Img1;
img.setAttribute("class", "banner-img");
img.setAttribute("alt", "effy");
document.getElementById("img-container").appendChild(img);
});
</script>
<img id="img-container" alt=" " class="img-responsive" />
<h5>
<a target="_blank" href="<?php echo $row['product_url']; ?>">
<?php echo $row['product_title']; ?>
</a>
</h5>
<?php echo $row['maximum_price']; ?>
<?php } ?>
我不知道的JavaScript,以及如何想法從json中獲取每個圖像並將其顯示在不同的標籤中。請幫助...在此先感謝
該json包含多個不同大小的圖像。你想要多大的尺寸? – abhishekkannojia
我必須將它們中的每一個取出並顯示在不同的img標籤中,怎麼辦? –