如何自動總結tfoot中的「總時數」數據並保存到MySQL數據庫並在同一區域重新顯示?我有兩個例子工作,我想添加自動求和功能的VizaHours網絡應用程序。如何自動求和列並保存到MySQL數據庫?
工作的例子在這裏:
EDITED 14年4月2日下面加所有代碼index.php
:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>
<body>
<table>
<thead>
<tr>
<th> DAY </th>
<th> DAY INFO </th>
<th> HOURS </th>
</tr>
<tfoot>
<tr id="summation">
<td class="total-hours" colspan="2">TOTAL HRS >>>>></td>
<td><span>0</span></td>
</tr>
<tr>
<th colspan="3">BUD HOURS - START WEEK 3-24-14<br />unpaid</th>
</tr>
</tfoot>
</thead>
<tbody>
<?php
include('connect.php');
$result = $db->prepare("SELECT * FROM budsvizahours ORDER BY id DESC");
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['fname']; ?><br /><br /><a href="editform.php?id=<?php echo
$row['id']; ?>"> Edit </a></td>
<td><?php echo $row['lname']; ?></td>
<td><?php echo $row['age']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>
EDITED 14年4月2日下面加所有代碼edit.php
:
<?php
// configuration
include('connect.php');
// new data
$lname = $_POST['lname'];
$fname = $_POST['fname'];
$age = $_POST['age'];
$id = $_POST['memids'];
// query
$sql = "UPDATE budsvizahours
SET fname=?, lname=?, age=?
WHERE id=?";
$q = $db->prepare($sql);
$q->execute(array($fname,$lname,$age,$id));
header("location: index.php");
?>
EDITED 14年4月2日下面加所有代碼editform.php
:
<?php
include('connect.php');
$id=$_GET['id'];
$result = $db->prepare("SELECT * FROM budsvizahours WHERE id= :userid");
$result->bindParam(':userid', $id);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<form action="edit.php" method="POST">
<input type="hidden" name="memids" value="<?php echo $id; ?>" />
<br>
<input type="hidden" name="fname" value="<?php echo $row['fname']; ?>" /><br>
Update Day Info<br>
<input type="text" name="lname" value="<?php echo $row['lname']; ?>" /><br>
Hours This Day<br>
<input class="record" type="tel" name="age" value="<?php echo $row['age']; ?>" />
<br><br>
<button class="edit-info-button" type="submit" value="Save">Save</button>
</form>
<?php
}
?>
<script>
$(document).ready(function(){
//iterate through each textboxes and add keyup
//handler to trigger sum event
$(".txt").each(function() {
$(this).keyup(function(){
calculateSum();
});
});
});
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".txt").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value); }
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#sum").html(sum.toFixed(2));
}
</script>
</body>
</html>
我只能看到一個HTML表。你的PHP邏輯在哪裏? – Raptor
謝謝Raptor ... new to posting here ...現在所有的代碼,但MySQL connect.php頁面。 :) – Bigfootbud