单击存储在MySQL数据库表中的图像,获取该图像的附加行内容



我创建了一个连接到数据库表的members.php页面。该表包含以下字段:id、用户名、配置文件图像。

下面的PHP代码以6行的形式显示每个用户的配置文件图像,并允许每个图像都是可点击的。

<?php
// The code below will display the current users who have created accounts with:  **datemeafterdark.com**
$result=mysql_query("SELECT * FROM profile_aboutyou");
$row1 = mysql_fetch_assoc($result);

$id = $row1["id"];
$_SESSION['id'] = $id;

$profileimagepath = $row1["profileimagepath"];
$_SESSION['profileimagepath'] = $profileimagepath;


$count = 0;
while($dispImg=mysql_fetch_array($result))
{
if($count==6) //6 images per row
{
print "</tr>";
$count = 0;
}
if($count==0)
print "<tr>";
print "<td>";
?>                          
<center>
<a href="viewmemberprofile.php"><img src="<?php echo $dispImg['profileimagepath'];?>" width="85px;" height="85px;"></a>
</center>
<?php
$count++;
print "</td>";
}           
if($count>0)
print "</tr>";

?>

然而,这一切都很好,当我点击加载的图像时,它会将我重定向到:viewmemberprofile.php,这就是它应该做的。但无论我点击哪个图像,它总是显示具有相同id值(即150(的相同图像。我希望发生的事情是。如果我点击id为155等的图像,无论我点击哪个图像,它都会显示该图像数据字段的内容,而不是一致的相同图像数据。

非常感谢您的帮助和指导。提前谢谢

我忘记提到的一件事是,我确实使用会话,所以…当我被重定向到viewmemberprofile.php页面时,我使用以下代码来帮助从表中获取我需要的数据。

<?php
$id = $_SESSION['id'];
echo($id);
?>
<?php
echo('<br>');
?>
<?php
$profileimagepath = $_SESSION['profileimagepath'];
?>
<img src="<?php echo($profileimagepath);?>" width="50px;" height="50px;">

我还没有提出建议的解决办法。

您需要将行的ID传递给viewmemberprofile.php,例如:

<a href="viewmemberprofile.php?id=<?= $dispImg['profileimagepath'] ?>">

viewmemberprofile.php需要从DB:中选择该行

SELECT * FROM profile_aboutyou WHERE id = $_GET['id']

上面的SQL语句是伪代码;您需要编写实际的代码来完成它所描述的内容,最好使用参数化查询。

最新更新