Jump to content

Using the SUM function.


vomitbomb

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.