2013-05-17 160 views
-1

我有一個函數可以使用friend_array字段從MySQL表中檢索朋友列表。朋友用戶的顯示列表不顯示所有用戶

但問題是,瀏覽器不顯示多個圖片,但它顯示默認的一個。

這是代碼

<?php 
//***********************Displaying Friend List*************************// 
$friendList = ""; 
$friendListTitle=""; 
if($friend_array!="") 
{ 
    $friendArray = explode(",", $friend_array); 

    $friendArray = array_slice($friendArray,0,6); 
    $friendCount = count($friendArray); 
    $friendListTitle = '<div class="title"> '.$username.'\'s Friends('.$friendCount.')</div>'; 
     //iterating to retrieve what it's needed as values 
/*$frnd1 = $friendArray[0]; 
$frnd2 = $friendArray[1]; 
/*$frnd3 = $friendArray[2]; 
$frnd4 = $friendArray[3]; 
$friendList .='<div style="background-color:"#CCC";>'.$frnd1.'<br />'.$frnd2.'</div>';*/ 

     $i=0; 
     $friendList ='<div style="background-color:"#CCC"; >'; 
     foreach($friendArray as $key => $value) 
     { 
      $i++; 
      $check_pic = "members/$value/image01.jpg"; 
      if(file_exists($check_pic)) 
      { 
       $frnd_pic = '<a href="profile.php?user_id='.$value.'"><img src = \"$check_pic\" width = "52px" border = "1"/></a>'; 
      } 
      else 
      { 
       $frnd_pic = '<a href="profile.php?user_id='.$value.'"><img src = "members/0/image01.jpg" width = "52px" border = "1"/></a>&nbsp;'; 
      } 
      $sqlName = mysql_query("SELECT first_name, last_name FROM members WHERE user_id= '$value'LIMIT 1") or die(mysql_error()); 
      if($row = mysql_fetch_array($sqlName,MYSQL_ASSOC)) 
      { 
       $fname = $row['first_name']; 
       $lname = $row['last_name']; 
       $friendList = '<div title="'.$fname.' '.$lname.'">'.$frnd_pic.'</div>'; 
      } 
     } 
     $friendList.='</div>'; 
} 
?> 

回答

0

你的圖像和包含的朋友記錄的div是由一個記錄替換所以它顯示你朋友的最後一個記錄。 試試這個可以幫助你

$friendList = ""; 
$friendListTitle=""; 
if($friend_array!="") 
{ 
    $friendArray = explode(",", $friend_array); 

    $friendArray = array_slice($friendArray,0,6); 
    $friendCount = count($friendArray); 
    var_dump($friendCount); 
    $friendListTitle = '<div class="title"> '.$username.'\'s Friends('.$friendCount.')</div>'; 
    //iterating to retrieve what it's needed as values 
    $i=0; 
    $friendList ='<div style="background-color:"#CCC"; >'; 
    foreach($friendArray as $frndlist => $value) 
    { 
     $i++; 
     $check_pic = 'members/'.$value.'/image01.jpg'; 
     if(file_exists($check_pic)) 
     { 
      //storing each friend images separately 
      $frnd_pic[$i] = '<a href="profile.php?user_id='.$value.'"><img src = "'.$check_pic.'" width = "52px" border = "1"/></a>'; 
     } 
     else 
     { 
      $frnd_pic[$i] = '<a href="profile.php?user_id='.$value.'"><img src = "members/0/image01.jpg" width = "52px" border = "1"/></a>&nbsp;'; 
     } 
     $sqlName = mysql_query("SELECT first_name, last_name FROM members WHERE user_id= '$value'LIMIT 1") or die(mysql_error()); 
     if ($row = mysql_fetch_array($sqlName, MYSQL_ASSOC)) 
     { 
      $fname = $row['first_name']; 
      $lname = $row['last_name']; 
      $friendList .= '<div title="'.$fname.' '.$lname.'">'.$frnd_pic[$i].'</div>'; 
     } 
    } 
    $friendList.='</div>'; 

}

+0

還是一樣沒有改變它 – user2378026

+0

是所有圖像都被命名​​image01但默認圖像具有路徑成員/ 0/image01.jpg否則,如果用戶有一個圖像的路徑成員/'.$值。'/ image01.jpg – user2378026

+0

noo the problemm它只顯示一個和圖片,它是默認的一個 – user2378026

相關問題