2016-09-12 60 views
-4

我想從數據庫中檢索這些圖像。如何在html中從數據庫檢索多個圖像<img>標籤

I want to retrieve these images from database.

<html> 
<body> 
<?php 
$servername="localhost"; 
$username="root"; 
$pass=""; 
$db="db"; 
$conn=new mysqli($servername,$username,$pass,$db); 

$result=$conn->query("select * from image"); 


    while($row_brand=mysqli_fetch_array($result)) 
    { 
     $brand_image=$row_brand['image']; 


    ?> 
<div class="div1"> 
<?php 
echo "<img src='uploads/$brand_image' />"; 
echo <img src="image.php?id=<? echo $image['id'];?>" /> 
    } 
?> 
</div> 
</body> 
</html> 

我使用此代碼來獲取所有圖像。
但我想在圖像<img>標記中獲取圖像。
所以請幫助我,我如何使用<img>標籤在html文件中獲取所有這些圖像。

+0

'$ image ['id']'這是從哪裏來的? – madalinivascu

+0

$ row_brand ['id']; insign of $ image ['id']; – JYoThI

+3

1.您正在覆蓋循環中的'$ brand_image'變量,2.您在顯示圖像時沒有使用循環,3.嘗試顯示ID時嘗試訪問不存在的變量。 – jeroen

回答

1
<html> 
<body> 
<?php 
$servername="localhost"; 
$username="root"; 
$pass=""; 
$db="db"; 
$conn=new mysqli($servername,$username,$pass,$db); 

$result=$conn->query("select * from image"); 


    while($row_brand=mysqli_fetch_array($result)) 
    { 
     $brand_image[] = $row_brand; 
    } 

    ?> 

<?php foreach($brand_image as $brand){ ?> 
<div class="div1"> 
<img src='uploads/<?php echo $brand["image"]; ?>' /> 
<img src="image.php?id=<? echo $brand['image_id']; ?>" /> 
</div> 
<?php } ?> 
</body> 
</html> 

請檢查此更新代碼。

+0

請檢查圖像中的前端 – omkar

+0

我想從圖像數據庫中獲取這六幅圖像 – omkar