• php 练习一 5月5日


    练习题一:通过登录者找到他的好友并显示在页面上

    <title>无标题文档</title>
    <style type="text/css">
    *
    {
    	margin:0px auto;
    	padding:0px;
    	}
    .hy
    {
    	200px;
    	height:50px;
    	margin-top:5px;
    	}
    .hy.hover
    {
    	background:#9CF;
    	cursor:pointer;
    	color:#FFF;}
    .pic
    {
    	50px;
    	height:50px;
    	float:left;
    	}
    .nk
    {
    	120px;
    	height:50px;
    	line-height:50px;
    	vertical-align:middle;
    	margin-left:30px;
    	float:left;
    	}
    
    </style>
    
    </head>
    
    <body>
    <?php
    $uid="18653378660";
    ?>
    
    <?php
    $db=new MySQLi("localhost","root","","weixin");
    !mysqli_connect_error() or die("连接失败!");
    $sql="select Friends from friends where Uid='{$uid}'";
    $result=$db->query($sql);
    $arr=$result->fetch_all();
    //循环读取好友的用户名
    foreach ($arr as $v)
    {
    	$fuid=$v[0];//好友的用户名
    	//根据好友的用户名在users表中查询出他的昵称和头像
    	$sqln="select NickName, Pic from users where Uid='{$fuid}'";
    	$resultn=$db->query($sqln);
    	$att=$resultn->fetch_row();
    	//输出头像$att[1]和昵称$att[0]
    	echo "<div class='hy' onclick='Select(this)'>
    	<div class='pic'><img src='{$att[1]}' width='50' height='50'/></div> 
    	<div class='nk'><img src='{$att[0]}'/></div>
    	<div>";
    	
    	}
    ?>
    
    </body>
    
    <script type="text/javascript">
    function Select(a)
    {
    	//清除所有选中的状态:
    	var div=document.getElementsByClassName("hy");
    	for(var i=0;i<div.length;i++)
    	{
    		div[i].style.backgroundColor="#FFF";
    		div[i].style.color="#000";
    		}
    	
    	//设置选中时的状态:
    	a.style.backgroundColor="#9CF";
    	a.style.color="#FFF";
    	}
    
    </script>
    

      

    附:以前没学好的一点内容:float

    <style>

    .a
    {
    200px;
    height:50px;
    float:left;}


    </style>

    </head>

    <body>
    <div class="a">aa</div>
    <div class="a">bb</div>
    <div class="a">cc</div>
    <div class="a">dd</div>
    <div class="a">ee</div>
    <div class="a">ff</div>

    <div style="background:#60F; 400px; height:100px;">ww</div>

    </body> 

    如何截断流:<div style="clear:both"></div>

    <body>
    <div class="a">aa</div>
    <div class="a">bb</div>
    <div class="a">cc</div>
    <div class="a">dd</div>
    <div class="a">ee</div>
    <div class="a">ff</div>
    <div style="clear:both"></div> <!--截断流-->

    <div style="background:#60F; 400px; height:100px;">ww</div>

  • 相关阅读:
    sqlite3中给表添加列
    webpack打包后服务端__dirname失效问题
    nodejs查看本机hosts文件域名对应ip
    vscode远程调试node服务端
    git 删除错误commit
    npm安装模块没有权限解决办法
    node gyp编译所需要的环境
    npm和yarn的淘宝镜像添加
    笨办法学Python 笔记
    梯度下降法优化线性回归算法参数
  • 原文地址:https://www.cnblogs.com/ds-3579/p/5461099.html
Copyright © 2020-2023  润新知