Single Result From SUM With MySQLi
Whatever is given in the SELECT statement to mysqli_query is going to return a mysql_result type if the query was successful. So if you have a SELECT statement such as:
SELECT sum(field) FROM table1
you still need to fetch the row with the result, and the value of the sum() function will be the only entry in the row array:
$res = mysqli_query($dbh,'SELECT sum(field) FROM table1');
$row = mysqli_fetch_row($res);
$sum = $row[0];
Sum of column in using mysqli and php
Try this:
<?php
require('connection.php');
$sql="SELECT sum(amount) as total FROM td";
$result = mysqli_query($sql);
while ($row = mysqli_fetch_assoc($result))
{
echo $row['total'];
}
mysqli_close($con);
?>
As said in a comment above, you don't need the ! infront of the query method.
simple echo SUM and Group by from mysqli
if you group by client_id then you should not select id and date
$sqlquery = "SELECT client_id, SUM(item) AS total_sales
FROM test
WHERE date BETWEEN '".$q_billing."' AND '2018-12-31'
GROUP BY client_id ";
show sum result group by date mysqli
I see 2 errors in your query:
- You are grouping by order_id when you should be grouping by
order_date
. - When multiplying values on the query, you should
SUM
the result of the operation, but you are summing its factors.
That said, your query should be:
SELECT
*,
SUM(order_quantity * order_price) as total
FROM
o_orders_f
GROUP BY
order_date
php mysqli query if i add sum or count it doenst work
If you want relative sumarization, you need to group your data with GROUP BY
SELECT band_naw, SUM(punten) AS punten FROM resultaat GROUP BY band_naw
Related Topics
Pass Value from HTML Form to PHP Without Submitting the Form
Getting Data from Post Array in Codeigniter
Set_Error_Handler() Doesn't Work for Fatal Error
Quoting Constants in PHP: "This Is a My_Constant"
How to Stop Curl from Using 100 Continue
Perl Equivalent of PHP's Escapeshellarg
Serial Comm with PHP on Windows
Given an Email as Raw Text, How to Send It Using PHP
Is There a Call_User_Func() Equivalent to Create a New Class Instance
Simulate PHP Array Language Construct or Parse with Regexp
Php: What Is the Complexity [I.E O(1),O(N)] of the Function 'Count'
Pdoexception' with Message 'Sqlstate[22001]: String Data, Right Truncated: 0
How to Use MySQL Found_Rows() in PHP