vomitbomb Posted May 12, 2008 Share Posted May 12, 2008 Trying to work out how to count all the items in a selected column. Here is my code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>counting Total..</title> </head> <?php // Make a MySQL Connection $conn = mysql_connect("localhost", "", ""); mysql_select_db("example", $conn); $howmany = $_POST['howmany']; $query = "SELECT SUM('$howmany') FROM orders"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); echo "How many?: ".$row['SUM($howmany)']; ?> <body> </body> </html> It was working fine till I tried to parse the $howmany variable into it. Link to comment https://forums.phpfreaks.com/topic/105246-using-the-sum-function/ Share on other sites More sharing options...
r-it Posted May 12, 2008 Share Posted May 12, 2008 try this $query = "SELECT SUM($howmany) FROM orders"; Link to comment https://forums.phpfreaks.com/topic/105246-using-the-sum-function/#findComment-538907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.