title: PHP store total count in a variable for each specific MySQL column value
body: <p>Im trying to create a Day Closure for our factory (employees). </p>
  
  <p>What I have created so far:</p>
  
  <ul>
  <li><p>It show's a total of all records in the database with startdate and status as given into the SQL SELECT function. So $totalWorkedTime = 16.68. But this is not what I want. I want to show for each department the total value.</p>
  
  <pre><code>$datestring = '23-10-2017';
  $qClosure = 'SELECT * FROM timeRegistration WHERE startdate="'. $datestring .'" &amp;&amp; status="3" ';
  $rClosure = mysqli_query($conn, $qClosure);
  
  $totalWorkedTime = 0;
  
  while($row = mysqli_fetch_assoc($rClosure)) {
  
  $totalWorkedTime += $row['worktime'];
  
  }
  echo $totalWorkedTime;
  </code></pre></li>
  </ul>
  
  <p>My goal is as following:</p>
  
  <ul>
  <li>A function which stores for the different departments (1, 2, 3, 4, 5, 6) a total count of worked hours. In my MySQL Database I have a column called: worktime. In this column I have different values like: 3.42, 3.42, 4.92, 4.92 (these are hours). So I have 4 records right. Now these records have different departments which stored in the column: department. </li>
  </ul>
  
  <p>I want that my function stores those values for each department. How can I manage this? An example is:</p>
  
  <p>$totalhoursDepartment5 = 6.84;
  $totalhoursDepartment4 = 9.84;</p>
  
  <p>The function should create more $totalhoursDepartment if is there any other records with department: 3 or 2 (example).</p>
  
  <p><a href="https://i.stack.imgur.com/haHFm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/haHFm.png" alt="MySQL DB"></a></p>