如何显示来自 MySql 的多个图像 [英] How to display multiples images from MySql

查看:41
本文介绍了如何显示来自 MySql 的多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 Html 中显示来自 MySQL 的多个图像.

我有两个文件:photogallery.php 用于显示图像,gallery.php 用于我的 php 代码.这有效,但我只能显示 1 张图片,我看不到所有图片!

这是用于显示照片的 photogallery.php 的代码:

<img src='gallery.php' height='95' width='95'/>

这是gallery.php的代码:

session_start();$host = "本地主机";$用户名 = "root";$密码 = "";$db_name = "照片";$tbl_name="画廊";mysql_connect("$host","$username","$password") 要么死 ("error22");mysql_select_db("$db_name") 或 die("error2");$username=$_SESSION['用户名'];$query= mysql_query("SELECT * FROM $tbl_name where username='$username'");while($row= mysql_fetch_assoc($query)){$imageData=$row["image"];//header("content-type:image/jpeg");回声 $imageData;}

谢谢!

解决方案

如果您使用 get_file_contents 之类的函数将图像数据存储在数据库中:

while($row= mysql_fetch_assoc($query)){$imageData=$row["image"];echo "<div align='left'>";echo " <img src='data:image/jpeg;base64,".base64_encode($imageData) ."'高度='95'宽度='95'/>";echo "</div>";}

I would like to know how to display multiples images from MySQL in Html.

I have two files: photogallery.php where I display the image and gallery.php where I have the php code. This works but I can only display 1 image and I can't see all images!

Here is the code for photogallery.php where I display the photo:

<div align='left'>
    <img src='gallery.php' height='95' width='95'/>
</div>

and here is the code for gallery.php:

session_start();

$host = "localhost";
$username = "root";
$password = "";
$db_name = "photos";
$tbl_name="gallery";


mysql_connect("$host","$username","$password")or die ("error22");
mysql_select_db("$db_name") or die("error2");

$ussername=$_SESSION['username'];

$query=  mysql_query("SELECT * FROM $tbl_name where username='$ussername'");

while($row= mysql_fetch_assoc($query)){

     $imageData=$row["image"];
     //header("content-type:image/jpeg");
     echo $imageData;
}

Thank you!

解决方案

If you have image data stored on the database with a function like get_file_contents :

while($row= mysql_fetch_assoc($query)){

     $imageData=$row["image"];

     echo "<div align='left'>";
     echo "  <img src='data:image/jpeg;base64," 
          . base64_encode($imageData) . "' height='95' width='95'/>";
     echo "</div>";
}

这篇关于如何显示来自 MySql 的多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆