I have a script with which I need to add the values of the columns, but the result appears as NaN. I need to add from the second column to the sixth. Are you taking values that are not numerical?
This is the script:
<script>
var totals=[0,0,0,0,0];
$(document).ready(function(){
var $dataRows=$("#mytable tr:not('.totalColumn, .titlerow')");
$dataRows.each(function() {
$(this).find('.rowDataSd').each(function(i){
totals[i]+=parseInt( $(this).html());
});
});
$("#mytable td.totalCol").each(function(i){
$(this).html(totals[i]);
});
});
</script>
This is PHP code:
<table id="mytable">
<thead>
<tr class="titlerow">
<th scope="col">Column1</th>
<th>Column2</th>
<th>Column3</th>
<th>Column4</th>
<th>Column5</th>
<th>Column6</th>
</tr>
</thead>
<tbody>
<tr>
<?php
include("conn.php");
$result = mysql_query("SELECT * FROM table1 GROUP BY name");
while($test = mysql_fetch_array($result))
{
$id = $test['id'];
echo"<td>".$test['name']."</td>";
echo"<td class='rowDataSd'>".$test['value1']."</td>";
echo"<td class='rowDataSd'>".$test['value2']."</td>";
echo"<td class='rowDataSd'>".$test['value3']."</td>";
echo"<td class='rowDataSd'>".$test['value4']."</td>";
echo"<td class='rowDataSd'>".$test['value5']."</td>";
echo "</tr>";
}
mysql_close($conn);
echo '<tfoot>
<tr class="totalColumn">
<td>.</td>
<td class="totalCol">Total:</td>
<td class="totalCol">Total:</td>
<td class="totalCol">Total:</td>
<td class="totalCol">Total:</td>
<td class="totalCol">Total:</td>
</tr>
</tfoot>';
?>
</table>