好友用户的显示列表未显示所有用户 [英] display list of friend user is not showing all users

查看:37
本文介绍了好友用户的显示列表未显示所有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数可以使用friend_array 字段从MySQL 表中检索朋友列表.

但问题是浏览器不显示多张图片,而是显示默认的一张.

这是代码

 
'.$username.'\'s Friends('.$friendCount.')</div>';//迭代以检索所需的值作为值/*$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 = "成员/$value/image01.jpg";如果(文件存在($check_pic)){$frnd_pic = '<a href="profile.php?user_id='.$value.'"><img src = \"$check_pic\" width = "52px" border = "1"/><;/a>';}别的{$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>';}?>

解决方案

包含好友记录的图片和 div 将被下一条记录替换,因此它会显示您好友的最后一条记录.试试这可能对你有帮助

$friendList = "";$friendListTitle="";if($friend_array!=""){$friendArray = expand(",", $friend_array);$friendArray = array_slice($friendArray,0,6);$friendCount = count($friendArray);var_dump($friendCount);$friendListTitle = '

'.$username.'\'s Friends('.$friendCount.')</div>';//迭代以检索所需的值作为值$i=0;$friendList ='<div style="background-color:"#CCC"; >';foreach($friendArray as $frndlist => $value){$i++;$check_pic = 'members/'.$value.'/image01.jpg';如果(文件存在($check_pic)){//分别存储每个朋友的图片$frnd_pic[$i] = '<a href="profile.php?user_id='.$value.'"><img src = "'.$check_pic.'" width = "52px" border = "1"/></a>';}别的{$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>';

}

I have a function that retrieve list of friends from the MySQL table using the friend_array field.

But the problem is that the browser doesn't show more than one picture, but it shows the default one.

this is the code

   <?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>';
}
?>

解决方案

you images and divs that contain the records of friends is being replaced by next record so it display the last record of your friends. try this may help you

$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>';

}

这篇关于好友用户的显示列表未显示所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆