2017-07-08 41 views
0

基本上我試圖創建一個用戶列表(userId,userName,userEmail和userPass)中的用戶(所有鏈接)在我的數據庫中的畫廊。當用戶將照片上傳到上傳目錄時,該信息會保存到名爲images(imgId,userId,imgName,imgLocation和uploadDate)的數據庫表中。我想要做的是從用戶表中提取用戶列表,當您單擊某個用戶時只顯示他們上傳的照片。php sql顯示來自不同貢獻者的圖像

我有這段代碼到目前爲止顯示列表中的用戶作爲鏈接。

<?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>'; 
?> 

我不知道如何將用戶鏈接到的圖像,然後顯示圖像的用戶列表的右側。我想使用保存在圖像表中的userId,無論何時提交圖像,但我完全丟失。

任何幫助將是偉大的(如果我有任何意義),仍然是相當新的這一點。

+0

你能否請你用兩個明確的句子向我解釋你想達到的目標? –

+0

我有一個我的頁面左側的註冊用戶列表,每個用戶名都是一個鏈接,我希望能夠按用戶名並能夠看到用戶上傳的所有照片。 – CallumB

回答

0

點擊用戶後,發送用戶id的請求,並使用此查詢獲取從圖像表中的圖像,

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

然後使用一個循環中,您可以通過循環標籤顯示圖像,

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