只有当我单击图像并且计数增加时,我才能使用任何方法来刷新图像?我不想刷新整个页面,因为如果刷新页面,点击计数器将需要再次从 0 开始计数。
<?php
include("connection.php");
$table1=mysql_query("select * from pic_a");
$table2=mysql_query("select * from pic_b");
$table3=mysql_query("select * from pic_c");
$tab1[0]=0;
$tab2[0]=0;
$tab3[0]=0;
$i=0;
while($row=mysql_fetch_assoc($table1))
{
$tab1[$i]= $row['pic_link'];
$i++;
}
$i=0;
while($row=mysql_fetch_assoc($table2))
{
$tab2[$i]= $row['pic_link'];
$i++;
}
$i=0;
while($row=mysql_fetch_assoc($table3))
{
$tab3[$i]= $row['pic_link'];
$i++;
}
$rand1=rand(0,9);
$rand2=rand(0,9);
$rand3=rand(0,9);
?>
<script type="text/javascript">
var count = 0;
function countClicks() {
count = count + 1;
document.getElementById("p2").innerHTML = count;
}
<table border="1">
<tr id="bird" onclick="countClicks();">
<td><img src="password\<?php echo $tab1[$rand1]; ?>" alt="" width="76" height="67"></td>
<td>Bird</td>
</tr>
<tr id="car" onclick="countClicks();">
<td><img src="password\<?php echo $tab2[$rand2]; ?>" alt="" width="76" height="67"></td>
<td>Car</td>
</tr>
<tr id="computer" onclick="countClicks();">
<td><img src="password\<?php echo $tab3[$rand3]; ?>" alt="" width="76" height="67"></td>
<td>Computer</td>
</tr>
</table>