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;
}