我有一个使用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> ';
}
$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>';
}
?>