Jump to content


Photo

How to display SQL Sum query in html?

sql html

Best Answer Jacques1, 01 April 2017 - 08:30 PM

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

Go to the full post


  • Please log in to reply
5 replies to this topic

#1 mal14

mal14
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 01 April 2017 - 07:11 PM

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, 01 April 2017 - 07:17 PM.


#2 emptry

emptry
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 01 April 2017 - 08:23 PM

is the coloum int ? :)

 

With html ? ..

I would use php and echo/print it :)


Edited by emptry, 01 April 2017 - 08:24 PM.


#3 mal14

mal14
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 01 April 2017 - 08:24 PM

is the coloum int ?

No, it's float :/



#4 mal14

mal14
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 01 April 2017 - 08:27 PM

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



#5 Jacques1

Jacques1
  • Members
  • PipPipPip
  • Turtles all the way down
  • 4,224 posts

Posted 01 April 2017 - 08:30 PM   Best Answer

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



#6 mal14

mal14
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 01 April 2017 - 08:32 PM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users