【发布时间】:2017-08-29 08:48:39
【问题描述】:
我有一个任务,我将解释我的工作应该是什么样的。
首先,我使用$.get方法从数据库中的表中获取总行数,并将值显示到html文件中。
1 小时或2小时或2天之后 或更长,表中的总行数会发生变化...
除了刷新页面或重新加载页面之外,我应该如何更新 html 文件中的总行数?
我的代码如下:
calculatetotalattack.php
<?php
include 'config.php';
$con = mysqli_connect ($dbhost, $dbusername, $dbpassword) or die ('Error in connecting: ' . mysqli_error($con));
//Select the particular database and link to the connection
$db_selected = mysqli_select_db($con, $dbname ) or die('Select dbase error '. mysqli_error());
//Make A SQL Query and link to the connection
$totalattackview = mysqli_query($con, 'SELECT * FROM attackview'); // get number of row from attackview
//Calculate the total number of rows from the table
$totalofrowsattack = mysqli_num_rows($totalattackview);
echo $totalofrowsattack;
mysqli_close($con);
?>
HTML
<html>
<head>
<title>Updating the Total Number of the total rows</title>
<script type="text/javascript" src="/Cesium-1.34/ThirdParty/jquery-1.11.3.min.js"></script>
</head>
<body>
<div id="totalattack"></div>
<script type="text/javascript">
function totalAttacks(val) {
$('#totalattack').html(val);
}
$.get({
url: 'calculateTotalAttack.php',
dataType: 'text',
success: totalAttacks
});
</script>
</body>
</html>
有办法吗?
【问题讨论】:
-
$.get获取行数或 setInterval/timeout 获取行数。 -
在这种情况下,您需要向表中动态添加行。
-
@Script47,除了 $.get 部分,我不明白你的句子..