鼠标点击显示详细信息

鼠标点击出现详细信息

数据库自己建哦 

 


showDetail.tpl

<table align="center">
<tr><th>显示用户信息</th></tr>
<tr style="background-color:'#ccc'">
<td>id</td>
<td>姓名</td>
</tr>
<{foreach from=$list item="value"}>
<tr style="background-color:'#ccc'">
<td id="name_<{$value.id}>"><{$value.id}></td>
<td οnmοuseοver="getdetail(<{$value.id}>)" οnmοuseοut="outone(<{$value.id}>)" ><{$value.name}></td>
</tr>
<{/foreach}>
</table>
<script>
function getdetail(user_id){
var xhr;
if(window.ActiveXObject){
   xhr = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}

xhr.open("POST","index.php?c=user&a=process",true);
xhr.onreadystatechange=callback;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
xhr.send("user_id="+user_id);

function callback(){
       if(xhr.readyState==4){
         if(xhr.status==200){
           //if(xhr.responseText)
    //alert("yes");
    var json = eval('('+xhr.responseText+')');
    var new_div = document.createElement("div");
    new_div.style.backgroundColor="red";
    new_div.style.position = "absolute";
    new_div.style.marginLeft = "140px";
    new_div.id ="new_div"+user_id;
    new_div.innerHTML ="id:"+json.id+"<br/>username"+json.name;
    document.getElementById("name_"+user_id).appendChild(new_div);
   
  }
       }
}
}
function outone(user_id){
var new_div = document.getElementById("new_div"+user_id);
  document.getElementById("name_"+user_id).removeChild(new_div);
}
</script>

useController.class.php

<?php
class userController extends baseController{
public function showDetailAction(){
$userModel = new userModel("localhost","liuyanban","root","123");
$rows = $userModel->searchall();
$this->smarty->assign("list",$rows);
$this->smarty->display("showDetail.tpl");
}
public function processAction(){
$user_id = $_REQUEST["user_id"];
$userModel = new userModel("localhost","liuyanban","root","123");
$row = $userModel->getone($user_id);

echo json_encode($row);

}

}
?>

userModel.class.php
<?php
class userModel extends baseModel{
public function getone($user_id){
   $sql = "select * from user where id=".$user_id;
   //file_put_contents("d://te.txt",$user_id,FILE_APPEND);
   $result = mysql_query($sql);
   $row =mysql_fetch_assoc($result);
   return $row;

}


public function selectAll($data){
   $sql = "select * from user where name like '{$data}%'";
   $result = mysql_query($sql);
   $rows = array();
 while($row = mysql_fetch_assoc($result)){
  $rows[] = $row;
 }
 //file_put_contents("d://s.txt",$sql,FILE_APPEND)
 return $rows;
}
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值