title: Get all dates from MySQL in the passed week and work out each days hours
body: <p>I am currently starting a punchclock for our work. This will log employees, In, Lunch Out, Lunch In and Out each day.</p>
  
  <p>I then would like to calculate times each week but specify the week too. So in MySQL lookup all dates in the selected week and then each day calculate the time between IN and OUT minus the lunch.</p>
  
  <p>I can't get my head around how best to do this.</p>
  
  <p>The table looks like:</p>
  
  <pre><code>id | user_id | punch_time | punch_status
  </code></pre>
  
  <p>The punch status' are:</p>
  
  <pre><code>In = 1
  Out = 0
  Lunch = 2
  </code></pre>
  
  <p>This is what i have already which is showing all the results in the past week.</p>
  
  <pre><code>   function getTotalHoursThisWeek($week)
     {
      include("db.php");
  
      $currUser = getUser('id');
      if($week == "CURRENT")
      {
           $query = "SELECT * FROM punch_clock WHERE YEARWEEK(`punch_time`, 1) = YEARWEEK(CURDATE(), 1) &amp;&amp; user_id = $currUser";
       } else {
           $query = "SELECT * FROM punch_clock WHERE YEARWEEK(`punch_time`, 1) = YEARWEEK($week, 1) &amp;&amp; user_id = $currUser";
      }
  
      $result = mysql_query($query) or die(mysql_error());
  
      while($row = mysql_fetch_array($result))
      {
           echo $row['punch_time']. "&lt;br /&gt;";
      }
  
  
   }
  </code></pre>
  
  <p>This outputs the following:</p>
  
  <pre><code>2015-04-29 17:04:00 - 0
  2015-04-29 08:38:03 - 1
  2015-04-30 17:20:00 - 0
  2015-04-30 09:19:23 - 1
  2015-05-01 09:09:47 - 1
  2015-05-01 12:36:44 - 2
  2015-05-01 12:57:58 - 1
  </code></pre>
  
  <p>However i would like to then take each day and then calculate the time from In(1) until Out(1) including any entry for Lunch out(2) and then back In(1) for that day.</p>
  
  <p>After that, add them all together to get the total time for that week.</p>