0
<?php
while($query_row2=mysql_fetch_array($result))
    {
    $res=mysql_query("SELECT * FROM images WHERE er='".$query_row2['er']."' ORDER BY `sr` DESC") or die ("Error");
    $q=mysql_fetch_array($res);
    $_SESSION["id1"]=$q['iname'];
?>


     <img src="xyz.php" height="50" width="100"/>
<?php

    }
?>

xyz.php 包含:

<?php
include("connection.php");
session_start();
$z= $_SESSION["id1"];
header ("Content-type:image");
echo $z;
?>

此代码显示为第一个 $query_row2['er'] 存储的相同图像......并且所有图像都显示相同..

4

1 回答 1

0

The behavior you encounter is normal: first, the page listing all the images is executed, so at the end, $_SESSION["id1"] will contain the content of the last image.

I would not use the session, and change your loop to:

while($query_row2=mysql_fetch_array($result)) {
    ?><img src="xyz.php?er=<?=urlencode($query_row2['er'])?>" height="50" width="100"/><?
}

and xyz.php to do the query to get the image content, so something like:

<?php
include("connection.php");
$res=mysql_query("SELECT * FROM images WHERE er='".mysql_real_escape_string($_GET['er'])."'");
$q=mysql_fetch_array($res);
$z = $q['iname'];
header ("Content-type:image");
echo $z;
?>
于 2013-04-17T21:39:52.110 回答