实现微信好友列表的php代码

时间:2023-03-09 19:47:39
实现微信好友列表的php代码
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*
{
margin:0px auto;
padding:0px;
font-family:微软雅黑;
}
#list
{
width:350px; height:400px;
}
.py
{
margin:8px 0px 0px 0px;
width:350px; height:35px;
}
.py:hover
{
background-color:#639;
color:#FFF;
cursor:pointer;
}
.img
{
width:35px; height:35px;
float:left;
}
.nc
{
float:left;
height:35px;
margin:0px 0px 0px 20px;
line-height:35px;
vertical-align:middle;
}
</style>
</head> <body>
<?php
$uid = "18653378660";
?> <div id="list"> <?php
//造连接对象
$db = new MySQLi("localhost","root","123","weixin");
//判断是否连接成功
!mysqli_connect_error() or die("连接失败!");
//写SQL语句
$sql = "select Friends from friends where Uid = '{$uid}'";
//执行SQL语句
$result = $db->query($sql); $attr = $result->fetch_all(); for($i=0;$i<count($attr);$i++)
{
//朋友的用户名
$fuid = $attr[$i][0]; //查USERS表,根据朋友的UID查出头像和昵称
$sqlf = "select NickName,Pic from Users where Uid='{$fuid}'"; $resultf = $db->query($sqlf); $attrf = $resultf->fetch_row(); echo "<div onclick='ShowCode(this)' class='py' bs='{$fuid}'>
<img class='img' src='{$attrf[1]}' />
<div class='nc'>{$attrf[0]}</div>
</div>"; } ?> </div>
<script type="text/javascript"> function ShowCode(div)
{
var d = document.getElementsByClassName("py");
for(var i=0; i<d.length;i++)
{
d[i].style.backgroundColor = "#FFF";
d[i].style.color = "#000";
}
div.style.backgroundColor = "#639";
div.style.color = "#FFF"; alert(div.getAttribute("bs"));
} </script>
</body>
</html>