Jump to content

mysql column total calculation


Mike
 Share

Recommended Posts

I wish to evaluate the tototal/sum of the sum column in the <tfoot> section of my table. I can't get the output correctly. my code is below. I shall appreciate any inputs. Take a look at the attached screen capture to better understand what i need to do. The total of the sum column in the table <tfoot> is what i need:

<?phprequire_once('includes/connect.php');$result = mysqli_query($con, "SELECT studentid, hw1, hw2, hw3, SUM(hw1+hw2+hw3) as sum FROM scores GROUP BY studentid");echo "<table border='1'><thead>	<tr>		<th>StudentID</th>		<th>HW1</th>		<th>HW2</th>		<th>HW3</th>		<th>SUM</th>	</tr></thead>";echo "<tfoot>    <tr>		<td>Total:</td>		<td> echo SUM(sum);</td>    </tr></tfoot>";while ($row = mysqli_fetch_array($result)){"<tbody>  <tr>";    echo "<td>" . $row['studentid'] . "</td>";    echo "<td>" . $row['hw1'] . "</td>";    echo "<td>" . $row['hw2'] . "</td>";    echo "<td>" . $row['hw3'] . "</td>";    echo "<td>" . $row['sum'] . "</td>";    echo "  </tr> </tbody>";	} echo "</table>"; mysqli_close($con);?>

Thankspost-96730-0-88029200-1388321386_thumb.jpg

Edited by Mike
Link to comment
Share on other sites

You're getting a parse error among other things aren't you?

 

http://www.php.net/manual/en/mysqli.query.php

 

See the Procedural style section. Your query isn't closing the dbl quote or paren.

Edited by niche
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...