[英]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.