How to sum a html table

I am trying the add the rows generated from my database to a table but i have completely no idea how to. I need to sum the td that has the id GP. Pleae Help, its really a problem

$connection = mysql_connect("localhost","root","");
	$mdata = $_POST["username"];
	
	$yr1_1st = mysql_query("SELECT * FROM trans_general WHERE semester = \\"first\\" AND level_offered = 100 AND regno =  '".$mdata."'", $connection);
	if(!$yr1_1st){
	die("Error2: " . mysql_error());
	
	}
	($num_rows = mysql_num_rows($yr1_1st));
	$row11 = mysql_fetch_array($yr1_1st);
$session_string = $row11["session"];
$session = (string)$session_string;
?>
<th scope="col">Year</th>
<th scope="col"> <?php $row11[$session]; ?></th>
<th scope="col">S/N</th>
<th scope="col">Code</th>
<th scope="col">Title</th>
<th scope="col">CR</th>
<th scope="col">Grade</th>
<th scope="col">GP</th>
</tr>
<tbody>
<?php
$mdata = $_POST["username"];

$stds = mysql_query("SELECT * FROM trans_general WHERE regno =  '".$mdata."'", $connection);

	if(!$stds){
	die("Error2: " . mysql_error());
	
	}
	$row2 = mysql_fetch_array($stds);

	$num_rows = mysql_num_rows($stds);

echo "$num_rows Rows\
";

	$connection = mysql_connect("localhost","root","");
	$mdata = $_POST["username"];
	
	$yr1_1st = mysql_query("SELECT * FROM trans_general WHERE semester = \\"first\\" AND level_offered = 100 AND regno =  '".$mdata."'", $connection);
	if(!$yr1_1st){
	die("Error2: " . mysql_error());
	
	}
	($num_rows = mysql_num_rows($yr1_1st));
	
	//Start While loop to generate data table
	while ($row11 = mysql_fetch_array($yr1_1st))
	{
	
$A=5;$B=4;$C=3;$D=2;$E=1;$F=0;$CR=$row11["credit_load"];

echo "$num_rows Rows\
";
echo "<tr>";
echo "<td scope=\\"col\\">Yr. 1</td>";
echo "<td scope=\\"col\\"></td>";
echo "<td scope=\\"col\\">"; for($sn = 1; $sn <= $num_rows; $sn++){echo $sn;} echo "</td>";
echo "<td scope=\\"col\\">"; echo $row11["course_code"]; echo "</td>";
echo "<td scope=\\"col\\">"; echo $row11["course_title"]; echo "</td>";
echo "<td scope=\\"col\\">"; echo $row11["credit_load"]; echo "</td>";

echo "<td scope=\\"col\\">";
if(($row11["score"])>69){echo "A";}
elseif(($row11["score"])>59){echo "B";}
elseif(($row11["score"])>49){echo "C";}
elseif(($row11["score"])>44){echo "D";}
elseif(($row11["score"])>39){echo "E";}
else{echo "F";}
echo"</td>";



echo "<td scope=\\"col\\" id = \\"GP\\">";
if(($row11["score"])>69){;echo $CR*$A;}
elseif(($row11["score"])>59){echo $CR*$B;}
elseif(($row11["score"])>49){echo $CR*$C;}
elseif(($row11["score"])>44){echo $CR*$D;}
elseif(($row11["score"])>39){echo $CR*$E;}
else{echo $CR*$F;}

echo "</td>";

echo "</tr>";
}//End While
	

You could do it using JS, although this may not be the best choice.
Can you post the HTML of your page (not PHP), or a link to a page where I can see the table?

Hi chris92, welcome to the forums

It may help if you put your trs and tds inside a table. eg.
output the table tags outside of the while loop.

It sounds like you could define a “sum” variable before the loop then += it inside the loop.

Thanks everyone, I just did the arithmetic using a query and sum() in my sql. Thanks again