如何从数据库中连续显示图像?

时间:2022-06-17 19:29:33

I want to retrieve the image from the database and want to display it in a row like if there is 20 images in a database then it should get display in 5 rows containing 4 images in each row... My code is working properly but i am facing problem in image path as i hv stored the image-name in database and image inside admin/uploads folder.... like uploads folder is inside the admin folder... adminfolder/uploadsfolder/file-name

我想从数据库中检索图像并希望将其显示在一行中,就好像数据库中有20个图像一样,它应该显示在5行中,每行包含4个图像...我的代码工作正常但是我我在图像路径中面临问题,因为我将图像名称存储在数据库中,而图像存储在admin / uploads文件夹中....就像uploads文件夹在admin文件夹中... adminfolder / uploadsfolder / file-name

here in my code i am getting problem in tracing the image path.....

在我的代码中,我在跟踪图像路径时遇到问题.....

I am Facing problem in this line.. // my all images is in admin/uploads folder

我在这一行遇到问题.. //我的所有图片都在admin / uploads文件夹中

echo "<td><img src=\"".$path[$i]."\" height='100'/></td>";

Here is my full code

这是我的完整代码

<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('dogs_db') or die(mysql_error());

$sql = "SELECT file_name FROM dogsinfo";
$res = mysql_query($sql) or die(mysql_error());
echo "<table><tr>";
while($fetch = mysql_fetch_assoc($res)) {
$path[] = $fetch['file_name'];
}

for($i=0;$i<count($path);$i++){

if($i%4 == 0){
echo "</tr>";
}
// I am Facing Problem here ... 
// my all images is in admin/uploads folder

echo "<td><img src=\"".$path[$i]."\" height='100'/></td>";

}
echo "</tr></table>";
?>

Please help me to sort out this....

请帮我解决这个问题....

1 个解决方案

#1


0  

How are within the admin/uploads folder, you must put in the src of the img tag.

如何在admin / uploads文件夹中,你必须放入img标签的src。

<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('dogs_db') or die(mysql_error());

$sql = "SELECT file_name FROM dogsinfo";
$res = mysql_query($sql) or die(mysql_error());
echo "<table><tr>";
while($fetch = mysql_fetch_assoc($res)) {
$path[] = $fetch['file_name'];
}

for($i=0;$i<count($path);$i++){

if($i%4 == 0){
echo "</tr>";
}
// I am Facing Problem here ... 
// my all images is in admin/uploads folder

echo "<td><img src=\"admin/uploads/".$path[$i]."\" height='100'/></td>";

}
echo "</tr></table>";
?>

#1


0  

How are within the admin/uploads folder, you must put in the src of the img tag.

如何在admin / uploads文件夹中,你必须放入img标签的src。

<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('dogs_db') or die(mysql_error());

$sql = "SELECT file_name FROM dogsinfo";
$res = mysql_query($sql) or die(mysql_error());
echo "<table><tr>";
while($fetch = mysql_fetch_assoc($res)) {
$path[] = $fetch['file_name'];
}

for($i=0;$i<count($path);$i++){

if($i%4 == 0){
echo "</tr>";
}
// I am Facing Problem here ... 
// my all images is in admin/uploads folder

echo "<td><img src=\"admin/uploads/".$path[$i]."\" height='100'/></td>";

}
echo "</tr></table>";
?>