zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    Node.js中流程控制
    设计模式六大原则(转)
    Python中装饰器(转)
    cocos2d-js反射
    With as
    Python中sort与sorted函数
    cocos+kbe问题记录
    Python字符串
    vue判断Object对象是否包含每个键
    vue跳转其他页面并传参
  • 原文地址:https://www.cnblogs.com/ds-3579/p/5461099.html
Copyright © 2011-2022 走看看