Q:

error with getting current week total amount from all rows with sql and php

I have multiple rows with each their total amount, I want to sum them up to get a single value for the current week.
I want to get the total sum amount for all rows for this current week and display it in a small widget.
<?php

  $query = "SELECT SUM(total_amount) as total_current_wk_amount FROM orders 
  WHERE yearweek(DATE(transaction_date), 1) = yearweek(curdate(), 1)";

  $total_current_wk_amount = $heidisql->prepare($query);
  $total_current_wk_amount->execute();
  $results = $total_current_wk_amount->fetch();

  ?>

  <div class="">Total Revenue: <?php echo $results[total_current_wk_amount]; ?></div>

Problem solved

A:

You have to get the result (by using a fetch method) instead of trying to display the statement object as a string.
<?php
$result = $total_current_wk_amount->fetch();
?>
<div class="">Total Revenue: <?php echo $result->total_current_wk_amount; ?></div>

