利用mvc制作热点显示具体信息


public function showDetailAction(){
$userModel=new userModel("localhost","news","root","123");
$row=$userModel->searchAll();
$this->smarty->assign('list',$row);
$this->smarty->display('showDetail.tpl');
}
public function searchAll(){
$sql="select * from new";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){
$rows[]=$row;
}
<table align="center">
<{foreach from=$list item=value}>
<tr style="background-color:#ccc">
<td id="name_<{$value.id}>"><{$value.id}></td>
<td Xonmouseover="onover(<{$value.id}>)" Xonmouseout="onout(<{$value.id}>)"><{$value.name}></td>
</tr>
<{/foreach}>
</table>
<script>
function onover(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=xixin',true);
xhr.Xonreadystatechange=callback;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send('id='+id); 
function callback(){
if(xhr.readyState==4){
if(xhr.status==200){
var json=eval('('+xhr.responseText+')');
var arr="id:"+json.id+"<br/>name:"+json.name+"<br/>"+json.dat;
var new_div=document.createElement('div');
new_div.style.backgroundColor="#ccc";
new_div.style.position='absolute';
new_div.style.marginLeft='70px';
new_div.id='id_'+id;
new_div.innerHTML=arr;
document.getElementById('name_'+id).appendChild(new_div);
}
}
}
}
function onout(id){
var new_div=document.getElementById('id_'+id);
document.getElementById('name_'+id).removeChild(new_div);
}
</script>
public function xixinAction(){
$id=$_REQUEST['id'];
$userModel=new userModel("localhost","news","root","123");
$row=$userModel->getOne($id);
$rows=json_encode($row);
echo $rows;
//echo $rows;
}
public function getOne($id){
$sql="select * from new where id='".$id."'";//file_put_contents('d:/f.txt',$sql,FILE_APPEND);
$res=mysql_query($sql); 
$row=mysql_fetch_assoc($res);
//var_dump($row);
return $row;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值