1

我有一个用 php 编码的表,它从 mysql 数据库中提取数据并将其显示在 html 表中。现在,当我单击一行时,我需要填充某些文本框。

最好的方法是什么:是使用数组还是 ajax、html 和 php,

<?php
$default = "<img src='http://localhost/on.png' width='24' height='24'/>";
 $default1 = "<img src='http://localhost/of.png' width='24' height='24'/>";
 $con = mysql_connect("*****","******","******");
if (!$con){
 die("Can not connect: " . mysql_error());
}
 mysql_select_db ("*****",$con);
$sql= "select act.*
 from audit_activity as act
  inner join (
      select user_id, max(timestamp) as max_ts
      from activity
      group by user_id) as a on act.user_id=a.user_id and act.timestamp=a.max_ts";
 $mydata = mysql_query($sql,$con);

 echo "<table id='tfhover',table border=0>
<tr>
 <th>Users</th>
 <th>Status<th>
</tr>";
while($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['user_id'] . "</td>";
if (strtolower(trim($record['activity']))!=strtolower('LOGIN')){ 
echo "<td>" . $default1  . "</td>";
}else{

 echo "<td>" . $default  . "</td>";
}



echo "</tr>";
}
echo "</table>";
;


mysql_close($con);

?>


<html>
<script type="text/javascript">
window.onload=function(){
var tfrow = document.getElementById('tfhover').rows.length;
var tbRow=[];
for (var i=1;i<tfrow;i++) {
    tbRow[i]=document.getElementById('tfhover').rows[i];
    tbRow[i].onmouseover = function(){
      this.style.backgroundColor = '#ffffff';
    };
    tbRow[i].onmouseout = function() {
      this.style.backgroundColor = '#d4e3e5';
    };
}
 };
  </script>
 <head>

 </head>
 <body>


  Total exams taken  : <br>
<input type="text" name="fname"/>
</body>

</html>
4

0 回答 0