我想通过使用数据库的列名“amount_no”和表中的“Amount”来打印每页的Amount列的总和。它的意思是命名为,在前端“Amount”和后端“amount_no”。现在我想使用这些名称之一来打印列的总和,而不是我在编码中使用的列编号(4)。请帮助我,因为我是一个PHP初学者。
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#example').DataTable( {
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column( 4 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Total over this page
pageTotal = api
.column( 4, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( 4 ).footer() ).html(
'Rs '+ pageTotal +' ( Rs '+ total +' total)'
);
}
} );
} );
</script>
PHP程式码:
<tfoot>
<tr>
<th colspan="5" style="text-align:right">Total:</th>
<th></th>
</tr>
</tfoot>
<tbody style="font-size:12px;">
<?php
while ($row = mysql_fetch_array($find))
{
$id = $row['id'];
$receipt_no = $row['receipt_no'];
$name = $row['name'];
$on_account = $row['on_account'];
$deceased_name = $row['deceased_name'];
$subDate = $row['subDate'];
$others = $row['others'];
$amount_no = $row['amount_no'];
$amount_word = $row['amount_word'];
$currency = $row['currency'];
$payment = $row['payment'];
$cheque_draft_no = $row['cheque_draft_no'];
$total_amount += $amount_no;
echo '<tr>';
foreach($_POST['field'] as &$field_value) {
switch ($field_value) {
case '1':
echo '<td><input name="selector[]" class="checkbox1" id="edit-delete" type="checkbox" value="' . $id . '"></td>';
break;
case '2':
echo '<td>' . $receipt_no . '</td>';
break;
case '3':
echo '<td>' . $name . '</td>';
break;
case '4':
echo '<td>' . $on_account. '</td>';
break;
case '5':
echo '<td>' . $deceased_name. '</td>';
break;
case '6':
echo '<td>' . $subDate. '</td>';
break;
case '7':
echo '<td>' . $others. '</td>';
break;
case '8':
echo '<td>' . $amount_no. '</td>';
break;
case '9':
echo '<td>' . $amount_word. '</td>';
break;
case '10':
echo '<td>' . $currency. '</td>';
break;
case '11':
echo '<td>' . $payment. '</td>';
break;
case '12':
echo '<td>' . $cheque_draft_no. '</td>';
break;
}
}
?>
<?php echo '</tr>';
}
?>
1条答案
按热度按时间9rnv2umw1#
这是一个有点难以理解实际上你的意思,也许试图解释某种不同的分离代码等。
但据我所知,你有一个数据库,你想从你的列所有数据的总和,为什么不这样做的SQL?
http://www.w3schools.com/sql/sql_func_sum.asp