php - 如何将图像从php显示到另一个
问题描述
我想在页面 index.php 的界面中显示数据库中的所有图像
<?php while($row = $result->fetch_assoc()) { ?>
<table border="1" width="702" height="149" align="center">
<tr>
<td width="148"><img src='get.php' width='200' height='211' /> </td>
</tr>
</table>
<?php } ?>
get.php 中的代码
<?php
include ("config.php");
$image = mysql_query ("SELECT image.image FROM image JOIN products
WHERE image.id = products.Image_ID");
$image = mysql_fetch_assoc ($image);
$image = $image ['image'];
header ("Content-type: image/jpeg");
echo $image;
?>
但它给了我一张在 index.php 中重复的图像。如何让代码从 index.php 中获取 Image_ID 以在同一页面中显示所有图像?
解决方案
这是你的 index.php
<?php while($row = $result->fetch_assoc()) { ?>
<table border="1" width="702" height="149" align="center">
<tr>
<td width="148"><img src='get.php?id='<?= $row['id'];?> width='200' height='211' /> </td>
</tr>
</table>
<?php } ?
并获取.php
<?php
include ("config.php");
$image = mysql_query ("SELECT image.image FROM image JOIN products
WHERE image.id = '".$_GET['id']."'");
$image = mysql_fetch_assoc ($image);
$image = $image ['image'];
header ("Content-type: image/jpeg");
echo $image;
?>
推荐阅读
- java - 单击按钮后如何使文本显示
- php - 如何将标准 php 函数传递给 array_map 和 array_filter?
- javascript - 理解 Javascript 中的 Promise
- c++ - 嵌套if else语句c ++
- matlab - 如何在不获取单个元素的情况下将数组按元素分配给数组?
- linux - 用于匹配列并将新列从文件添加到表中的 shell 脚本
- hibernate - hbernate org.hibernate.PersistentObjectException:未初始化的代理传递给 org.hibernate.event.internal.DefaultSave 的 save()
- vba - 试图从工作表子调用模块子:'运行时错误:1004'
- spotipy - 无效的 spotipy 重定向 URL
- android - Xamarin Android 项目中不存在类型或命名空间名称“支持”