mal14 Posted April 1, 2017 Share Posted April 1, 2017 (edited) I've come up with an SQL sum query: $query = "SELECT SUM(calories) FROM tracklog AS calories WHERE userid = $_SESSION[userid]"; No errors are shown, however how do I get this value to be displayed using HTML? I want it to be displayed after 'Total number of calories lost to date:' Edited April 1, 2017 by mal14 Quote Link to comment https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/ Share on other sites More sharing options...
emptry Posted April 1, 2017 Share Posted April 1, 2017 (edited) is the coloum int ? With html ? ..I would use php and echo/print it Edited April 1, 2017 by emptry Quote Link to comment https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/#findComment-1544924 Share on other sites More sharing options...
mal14 Posted April 1, 2017 Author Share Posted April 1, 2017 is the coloum int ? No, it's float :/ Quote Link to comment https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/#findComment-1544925 Share on other sites More sharing options...
mal14 Posted April 1, 2017 Author Share Posted April 1, 2017 is the coloum int ? With html ? .. I would use php and echo/print it I tried doing this! while($row = mysqli_fetch_assoc($result)) { echo 'Calories burned to date: '.$row['calories']; } However, I keep getting any error saying calories is an undefined index Quote Link to comment https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/#findComment-1544926 Share on other sites More sharing options...
Solution Jacques1 Posted April 1, 2017 Solution Share Posted April 1, 2017 Yes, because there is no “calories” column in your result set. The only column is “SUM(calories)”. To get a more handy name, use an alias: SELECT SUM(calories) AS total_calories FROM ...; Then the column is called “total_calories”. Quote Link to comment https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/#findComment-1544928 Share on other sites More sharing options...
mal14 Posted April 1, 2017 Author Share Posted April 1, 2017 Yes, because there is no “calories” column in your result set. The only column is “SUM(calories)”. To get a more handy name, use an alias: SELECT SUM(calories) AS total_calories FROM ...; Then the column is called “total_calories”. Thank you!!! It works Quote Link to comment https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/#findComment-1544929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.