【问题标题】:How to display image in a row from database?如何从数据库中连续显示图像?
【发布时间】:2014-06-20 03:46:49
【问题描述】:

我想从数据库中检索图像并希望将其显示在一行中,例如如果数据库中有 20 个图像,那么它应该显示为 5 行,每行包含 4 个图像... 我的代码工作正常,但我在图像路径中遇到问题,因为我将图像名称存储在数据库中,并将图像存储在 admin/uploads 文件夹中......就像上传文件夹在管理文件夹中...... adminfolder/uploadsfolder/file -名称

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

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

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

这是我的完整代码

<?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>";
?>

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

【问题讨论】:

  • 返回$path[$i] 包含admin/uploads/file_name?

标签: php html mysql sql image


【解决方案1】:

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>";
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    相关资源
    最近更新 更多