標籤:
學習:查詢好友名單
<!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>*{marger:0px auto;padding:0px;}.hy{width:200px;height:50px;margin-top:5px;}/* //使用下邊的js之後,這些就不用了.hy:hover{background-color:#999;cursor:pointer;}*/.pic{width:50;height:50px;float:left;}.nk{height:50px;width:130px;float:left;margin-left:20px;line-height:50px;vertical-align:middle;}</style></head><body><?php$uid="18653378660";?><?php$db=new MySQLi("localhost","root","","mydb");$sql="select friends from friends where uid=‘18653378660‘";$result = $db->query($sql);$attr=$result->fetch_all();foreach($attr as $v){$fuid=$v[0];//好友的使用者名稱//根據使用者名稱查詢users表的暱稱和頭像$sqlu="select nickname pic from users where uid=‘{$fuid}‘";$r=$db->query($sqlu);$attr=$r->fetch_row();echo "<div class=‘hy‘ onclick=‘select(this)‘> <div class=‘pic‘><img width=‘50px‘ height=‘50px‘ src=‘{$attr[1]}‘/></div> <div class=‘nk‘>{$attr[0]}</div> </div>";}?></body><script type="text/javascript">function select(aa) //aa代表該div{//清除原選中狀態var div=document.getElementsByClassName("hy");for(var i=0;i<div.length;i++){div[i].style.backgroundColor="white";div[i].style.color="#000000";}//設定選中aa.style.bachgroundcolor="#60c";aa.style.color="while";}</script></html>
練習資料庫和網頁布局(查詢好友名單)