title: Php foreach date
body: <p>I got this:</p>
  
  <pre><code>foreach($result_set_cw_01 as $result_cw_01) {
  
      $newcw = mt_rand(1, 52);
  
      $week = $newcw;
      $year = date("Y");
      $time = mktime(0,0,0,1,1,$year) + ($week * 7 * 24 * 60 * 60);
      $time = $time - ((date('N', $time) - 1) * 24 * 60 * 60);
  
      $startWeek = date('Y-d-M', $time);
      $endWeek = date('Y-d-M', $time + (6 * 24 * 60 * 60));
  
      # Insert Random Calender Week
      $set = array(
                  'calender_week' =&gt; $week,
                  'start_week' =&gt; $startWeek,
                  'end_week' =&gt; $endWeek,
                  );
  
      $whereWeek = array('id = :id');
      $valuesWeek = array('id' =&gt; $result_cw_01['id']);
  
      $db-&gt;update($table, $set, $whereWeek, $valuesWeek);
  }
  </code></pre>
  
  <p>Let me explain what happens.
  I got a database with ids, users, names, calender_week, start_week and end_week.</p>
  
  <p>I basically get a random number between 1 and 52 with this line </p>
  
  <blockquote>
    <p>$newcw = mt_rand(1, 52);</p>
  </blockquote>
  
  <p>It stands for calender week.</p>
  
  <p>The next lines does calculate the starting day (monday) and the ending day (sunday) of that week for each number I have.</p>
  
  <p>Next I insert and update my new values into my database.</p>
  
  <p>Now what does not work is the update on <code>$startWeek</code> and <code>$endweek</code> into my database.</p>
  
  <p>If I echo out <code>$result_cw_01['calender_week']</code> I get the <code>$startWeek</code> and <code>$endweek</code> of the last user's calenderweek.</p>
  
  <p>But if I echo <code>$startWeek</code> and <code>$endWeek</code> I get the correct date for that specific calenderweek, but it just does not save it properly.</p>
  
  <p>Can anyone help.</p>
  
  <p>I changed update to select and echod it:
  $db->update($table, $set, $whereWeek, $valuesWeek);</p>
  
  <p>$db->select($table, $set, $whereWeek, $valuesWeek);</p>
  
  <pre><code>string 'SELECT 2,2015-01-12,2015-01-18 FROM staff  where id = :id' (length=57)
  
  string 'SELECT 49,2015-12-07,2015-12-13 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 26,2015-06-29,2015-07-05 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 11,2015-03-16,2015-03-22 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 11,2015-03-16,2015-03-22 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 51,2015-12-21,2015-12-27 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 39,2015-09-28,2015-10-04 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 9,2015-03-02,2015-03-08 FROM staff  where id = :id' (length=57)
  
  string 'SELECT 2,2015-01-12,2015-01-18 FROM staff  where id = :id' (length=57)
  
  string 'SELECT 25,2015-06-22,2015-06-28 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 24,2015-06-15,2015-06-21 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 7,2015-02-16,2015-02-22 FROM staff  where id = :id' (length=57)
  
  string 'SELECT 18,2015-05-04,2015-05-10 FROM staff  where id = :id' (length=58)
  
  string 'SELECT 27,2015-07-06,2015-07-12 FROM staff  where id = :id' (length=58)
  </code></pre>