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

  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2 <html xmlns="http://www.w3.org/1999/xhtml">
  3 <head>
  4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5 <title>无标题文档</title>
  6 <style type="text/css">
  7 *
  8 {
  9     margin:0px auto;
 10     padding:0px;
 11     font-family:微软雅黑;
 12 }
 13 #list
 14 {
 15     width:350px; height:400px;
 16 }
 17 .py
 18 {
 19     margin:8px 0px 0px 0px;
 20     width:350px; height:35px;
 21 }
 22 .py:hover
 23 {
 24     background-color:#639;
 25     color:#FFF;
 26     cursor:pointer;
 27 }
 28 .img
 29 {
 30     width:35px; height:35px;
 31     float:left;
 32 }
 33 .nc
 34 {
 35     float:left;
 36     height:35px;
 37     margin:0px 0px 0px 20px;
 38     line-height:35px;
 39     vertical-align:middle;
 40 }
 41 </style>
 42 </head>
 43 
 44 <body>
 45 <?php
 46     $uid = "18653378660";
 47 ?>
 48 
 49 <div id="list">
 50 
 51 <?php
 52     //造连接对象
 53     $db = new MySQLi("localhost","root","123","weixin");
 54     //判断是否连接成功
 55     !mysqli_connect_error() or die("连接失败!");
 56     //写SQL语句
 57     $sql = "select Friends from friends where Uid = ‘{$uid}‘";
 58     //执行SQL语句
 59     $result = $db->query($sql);
 60     
 61     $attr = $result->fetch_all();
 62     
 63     for($i=0;$i<count($attr);$i++)
 64     {
 65         //朋友的用户名
 66         $fuid = $attr[$i][0];
 67         
 68         //查USERS表,根据朋友的UID查出头像和昵称
 69         $sqlf = "select NickName,Pic from Users where Uid=‘{$fuid}‘";
 70         
 71         $resultf = $db->query($sqlf);
 72         
 73         $attrf = $resultf->fetch_row();
 74         
 75         echo "<div onclick=‘ShowCode(this)‘ class=‘py‘ bs=‘{$fuid}‘>
 76         <img class=‘img‘ src=‘{$attrf[1]}‘ />
 77         <div class=‘nc‘>{$attrf[0]}</div>
 78         </div>";
 79         
 80     }
 81     
 82     
 83     
 84 ?>
 85     
 86 </div>
 87 <script type="text/javascript">
 88     
 89     function ShowCode(div)
 90     {
 91         var d = document.getElementsByClassName("py");
 92         for(var i=0; i<d.length;i++)
 93         {
 94             d[i].style.backgroundColor = "#FFF";
 95             d[i].style.color = "#000";
 96         }
 97         div.style.backgroundColor = "#639";
 98         div.style.color = "#FFF";
 99         
100         alert(div.getAttribute("bs"));
101     }
102     
103 </script>
104 </body>
105 </html>

 

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

上一篇:99-js注意点、建议与规范


下一篇:vue项目中 页面组件懒加载使用webpackChunkName