title: How to get the sum in a column using MySQL and PHP
body: <p>I've been searching for the better part of five days (no joke, don't want to bother you guys for nothing), but I can't seem to be getting this right. I want to display the total amount of a column (tech) on the screen using a function in PHP. Don't worry, the $day part works in other functions. I don't think it is part of the problem. Thank you in advance.</p>
  
  <pre><code>function calc_tech($day){
  
      include("connect.php"); // include database connection
  
      $res = $mysqli -&gt; query(" SELECT * FROM sales WHERE day = $day ") or die($mysqli-&gt;error); // Fetch data from the table
  
      while($val = $res -&gt; fetch_array()){
          $tech_total = $val[tech] += $val[tech];
      }
  
      echo $tech_total; // Echo the result
      //echo "42";
  
      $res -&gt; free(); // Free the query results
      $mysqli -&gt; close(); // Close mysqli object
  
  }
  </code></pre>
  
  <p>My database table looks like this: </p>
  
  <p><a href="https://i.stack.imgur.com/hyksz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hyksz.png" alt="enter image description here"></a></p>