Jump to content

How to display SQL Sum query in html?


Go to solution Solved by Jacques1,

Recommended Posts

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 by mal14
Link to comment
https://forums.phpfreaks.com/topic/303596-how-to-display-sql-sum-query-in-html/
Share on other sites

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

  • Solution

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”.

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.