我有一个朋友列表,我希望使用php和mysql在个人资料页面中显示

时间:2013-05-17 12:31:21

标签: php html css

我有一个朋友列表,我希望使用php和mysql

显示在个人资料页面中

但问题是它显示列表垂直但我想要的是显示每行三个而不是连续每张图片

这是代码

<?php 
//***********************Displaying Friend List*************************//
$friendListTitle = "";
$friendList = "";
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
        $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))
            {
                $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());
            while($row = mysql_fetch_array($sqlName))
            {
                $fname = $row['first_name'];
                $lname = $row['last_name'];
                $friendList .= '<div title="'.$fname.' '.$lname.'">'.$frnd_pic.'</div>';
            }
        }
        $friendList.='</div>';
}
?>

1 个答案:

答案 0 :(得分:0)

尝试使div显示为内联块,因为默认情况下,DIV标记显示为块,占用整行空间并阻止其他人放置在那里;)
$friendList .= '<div title="'.$fname.' '.$lname.'" style="display:inline-block;">'.$frnd_pic.'</div>';