简体   繁体   English

如何使用php显示来自数据库mysql的图像?

[英]How to display images from database mysql using php?

I'm stacked about displaying images from database. 我堆满显示数据库中的图像。 I have code like this: 我有这样的代码:

// Get image
$image = "SELECT * FROM ".TABLE_PREFIX."mod_img WHERE section_id = '$section_id' ORDER BY number ASC";
$get_img = $database->query($image);
$img = $get_img->fetchRow();
//build images
function tampil($str){
    $arr = explode('-',trim($str));
    return $arr[0];
}
$imglist = '';
$curdir = $section_id."/";
if($img) {
    foreach($img as $im){
        $imglist .= '<div style="float:left; align="center";"><img style="margin:03px;" src="'.$baseurl.$curdir.'thumbs/'.$im['name'].'" alt="'.$baseurl.$curdir.$im['name'].'" title="'.$baseurl.$curdir.$im['number'].'"><figcaption><center>IMG '.$im['number'].'</center></figcaption></div>';
    }
}
else{
    $imglist .= '<i>No image yet</i>';  
}

But it doesn't work and there are warning : 但这不起作用,并且有警告:

Warning: Illegal string offset 'name' in C:\xampp\htdocs\wb\modules\pagina_toevoegen\modify.php on line 81
..................
..................

Please help me and sorry I'm new in programming. 请帮助我,对不起我是编程新手。

When I didn't use foreach looping, it works, but only displaying one image. 当我不使用foreach循环时,它可以工作,但仅显示一张图像。

Add while loop around your code and fix the rest of the code accordingly. 在代码周围添加while循环,并相应地修复其余代码。

  while ($img = $get_img->fetchRow()) {

    }

in your case 在你的情况下

$img = $get_img->fetchRow();

fetches only one row and you dont see the rest of the rcords 仅获取一行,您看不到其余的rcord

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PHP从数据库显示图像? - How to display images from a database using PHP? 如何使用PHP显示存储在mysql数据库中的图像 - how to display images stored in a mysql database using PHP 如何直接从mysql数据库中获取图像并使用php以json格式显示它们? - How to fetch images from mysql database directly and display them in json format using php.How to do this? 如何从mysql数据库检索图像文件路径并使用php显示图像 - How to retrieve image file paths from mysql database and display the images using php 如何使用PHP显示随机图像而不重复数据库(MySql) - How to display the random images without repetition from database(MySql) using php 如何将图像插入数据库并从数据库中获取并使用 PHP 显示? - How to insert images into the database and fetch it from the database and display using PHP? 如何使用php从mysql显示多个图像(blob)? - how to Display Multiple Images (blob) from mysql using php? 如何使用选项在php中显示数据库中的图像并选择 - How to display images from a database in php using option and select 如何使用MYSQLi查询从数据库中显示php中的图像? - how to display images in php from database using MYSQLi queries? 如何使用幻灯片在php中显示数据库中的多个图像 - how to display multiple images in php from database using slideshow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM