2016-09-12 42 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