2011-05-25 27 views
0

在我的網站上顯示用戶好友,但沒有他們的個人資料照片嗎?獲取不同人的用戶詳細信息

我有2個數據庫。一個是用戶,那就是我保存所有用戶的詳細信息。第二個數據庫有,如果他們是朋友呢?

我的問題是如何從用戶表中獲取他們的個人資料照片。

p.s.輪廓PIC行Proimg

這是我的代碼

 
In the 2nd database i have the friends details 
id Sender Receiver Accepted 
1 bob bill  1 
2 fred bill  3 

接受:

 
1 means that they havent accepted or declined 
2 means that they have accepted 
3 means that they have declined 

在第1表我有用戶的詳細信息...

 
id Fullname Password proimg birthday 
1 bill  ****  hi.jpg 1991-01-01 
2 bob  ****  hello.jpg 1991-07-02 
3 fred  ****  hey.jpg 1991-10-05 
<?php 

    $term = $fullname; 
    $sql12 = mysql_query("select * from Friends where Reciver like '%$term%' or Sender like '%$term%'"); 
    $Friends = mysql_num_rows($sql12); 

    $t=1; 
    while($t<=$Friends) 
     { 
     while ($row = mysql_fetch_array($sql12)) 
     { 
     If ($row['accepted'] == 2) 
     { 
     Echo '<img src="images/defaultprof.png" width="45px" height="45px"/>'; 
     } 
     else 
    { 
    $_SERVER['PHP_SELF']; 
    } 
    } 
     $t++; 
    } 
    ?> 
+0

您能否顯示數據庫中每個表有哪些字段? – 2011-05-25 06:53:13

+0

更好嗎? – Ryan 2011-05-25 07:04:09

+0

'發件人'和'收件人'是什麼類型的字段?如果他們是varchar類型,那麼我強烈建議你從兩個用戶的表1中存儲用戶id。 – 2011-05-25 07:13:16

回答

3

你會大概想要INNER JOIN的朋友的用戶數據。這可以這樣來完成:(根據組成的課程表)。

SELECT f.*, u.proImg FROM friends AS f 
INNER JOIN users AS u ON u.userID = f.friendID 
WHERE f.userID = 1; 

閱讀整個JOIN語法here

+0

F是朋友表是嗎? – Ryan 2011-05-26 08:54:20

+0

是的,請參閱'朋友AS f' – 2011-05-26 09:01:45

+0

謝謝生病嘗試 – Ryan 2011-05-26 09:12:21

相關問題