首页 > 解决方案 > 如何将图像从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 以在同一页面中显示所有图像?

标签: phphtmlsql

解决方案


这是你的 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;
?>

推荐阅读