DanielWhite Posted June 25, 2008 Share Posted June 25, 2008 Hey, Does anyone know why this won't work: mysql_query("SELECT SUM(InkCosts) FROM Stats WHERE Month='$MONTH' AND Year='$YEAR'"); The table name is correct, The $MONTH variable is working. The $YEAR variable is working. The InkCosts is the right field name. The code below; $INK = mysql_query("SELECT SUM(InkCosts) FROM Stats WHERE Month='$MONTH' AND Year='$YEAR'"); echo $INK; Prints this: Resource id #4 Thank you, Daniel White. Link to comment https://forums.phpfreaks.com/topic/111759-mysql-sum-query/ Share on other sites More sharing options...
hitman6003 Posted June 25, 2008 Share Posted June 25, 2008 You have to get the result of your query out of the "Resource" returned by the query... $INK = mysql_query("SELECT SUM(InkCosts) FROM Stats WHERE Month='$MONTH' AND Year='$YEAR'"); echo mysql_result($INK, 0); Link to comment https://forums.phpfreaks.com/topic/111759-mysql-sum-query/#findComment-573725 Share on other sites More sharing options...
ohdang888 Posted June 25, 2008 Share Posted June 25, 2008 or: $INK = mysql_query("SELECT SUM(InkCosts) FROM Stats WHERE Month='$MONTH' AND Year='$YEAR'"); $INK = mysql_fetch_array($INK); $INK = $INK['SUM(InkCosts)']; echo $INK; Link to comment https://forums.phpfreaks.com/topic/111759-mysql-sum-query/#findComment-573833 Share on other sites More sharing options...
DanielWhite Posted June 25, 2008 Author Share Posted June 25, 2008 Thank you very much :-) I'm using this one: echo mysql_result($INK, 0); Link to comment https://forums.phpfreaks.com/topic/111759-mysql-sum-query/#findComment-573929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.