Mike Posted December 28, 2013 Share Posted December 28, 2013 (edited) 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);?> Thanks Edited December 29, 2013 by Mike Link to comment Share on other sites More sharing options...
niche Posted December 29, 2013 Share Posted December 29, 2013 Where's your right paren and dbl quote? Link to comment Share on other sites More sharing options...
niche Posted December 29, 2013 Share Posted December 29, 2013 and don't forget error reporting http://www.w3schools.com/php/func_mysqli_error.asp Link to comment Share on other sites More sharing options...
Mike Posted December 29, 2013 Author Share Posted December 29, 2013 Where's your right paren and dbl quote? hi, I dont understand what you mean? Link to comment Share on other sites More sharing options...
niche Posted December 29, 2013 Share Posted December 29, 2013 (edited) 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 December 29, 2013 by niche Link to comment Share on other sites More sharing options...
davej Posted December 29, 2013 Share Posted December 29, 2013 I look at it and see obvious errors in the table that anyone would see, so fix those. Also test your sql query with a better example. I think SUM() will fail to do what you expect. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now