【问题标题】:i have a list of friends that i want to be displayed in the profile page using php and mysql我有一个朋友列表,我想使用 php 和 mysql 在个人资料页面中显示
【发布时间】:2013-05-17 20:48:22
【问题描述】:

我有一个朋友列表,我想使用 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>';
}
?>

【问题讨论】:

  • for($i=0,$i
  • 如果您的问题是关于布局/对齐的,那么您应该在 HTML/CSS 下标记它
  • 你不是在谈论 php 和 Mysql,你的问题是 CSS 和 html
  • 这个问题的重复stackoverflow.com/questions/16602315/…再次相同的代码...
  • @ jcho360 @ php NoOb 我知道这是一个 html 和 css 但在 php 中,如你所见

标签: php html css


【解决方案1】:

尝试让 div 显示为 inline-block,因为默认情况下 DIV 标签显示为块,占用一整行空间并防止其他人被放置在那里;)
$friendList .= '&lt;div title="'.$fname.' '.$lname.'" style="display:inline-block;"&gt;'.$frnd_pic.'&lt;/div&gt;';

【讨论】:

  • 感谢 Benas Radzevicius 的帮助,我会尽快支持你
猜你喜欢
  • 2011-10-12
  • 2016-11-26
  • 2016-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-27
相关资源
最近更新 更多