php sql显示来自不同贡献者的图像

时间:2017-07-08 14:38:52

标签: php mysql

基本上我正在尝试创建一个图库,其中包含从我的数据库中的用户表(userId,userName,userEmail和userPass)中提取的用户列表(所有链接)。当用户上传照片时,它会保存到上传目录,但信息会保存到名为images(imgId,userId,imgName,imgLocation和uploadDate)的数据库表中。我想要做的是从用户表中提取用户列表,当您点击用户时,它只显示他们上传的照片。

到目前为止,我已将此代码用于将列表中的用户显示为链接。

<?php
ob_start();
session_start();
require_once 'dbconnect.php';

// if session is not set this will redirect to login page
if( !isset($_SESSION['user']) ) {
    header("Location: index.php");
    exit;
}
// select loggedin users detail
$res=mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>

<?php
$query = mysql_query("SELECT userName FROM `users`");

echo '<table>';
while($rowtwo = mysql_fetch_array($query)){
echo    '<tr>
        <td class="userlist"><font size="4" face="Lucida Sans Unicode"color="black"><a href="" >'.$rowtwo['userName'].'</a></td>
        </tr>';
   }
echo '</table>';
?>

我不知道如何将用户链接到图像,然后将图像显示在用户列表的右侧。我想使用每次提交图像时保存到images表的userId,但我完全迷失了。

任何帮助都会很棒(如果我有任何意义的话),对此仍然相当新。

1 个答案:

答案 0 :(得分:0)

点击用户后,在请求中发送userId并使用此查询从images表中获取图像,

select 'imgName', 'imgLocation' from images where userId = '$YourUserId';

然后使用循环,您可以通过循环标记显示图像,

<img src="IMAGE_LOCATION" alt="IMAGE_NAME" height="42" width="42">