Php foreach date

I got this:

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' => $week,
                'start_week' => $startWeek,
                'end_week' => $endWeek,
                );

    $whereWeek = array('id = :id');
    $valuesWeek = array('id' => $result_cw_01['id']);

    $db->update($table, $set, $whereWeek, $valuesWeek);
}

Let me explain what happens.
I got a database with ids, users, names, calender_week, start_week and end_week.

I basically get a random number between 1 and 52 with this line

$newcw = mt_rand(1, 52);

It stands for calender week.

The next lines does calculate the starting day (monday) and the ending day (sunday) of that week for each number I have.

Next I insert and update my new values into my database.

Now what does not work is the update on $startWeek and $endweek into my database.

If I echo out $result_cw_01[‘calender_week’] I get the $startWeek and $endweek of the last user’s calenderweek.

But if I echo $startWeek and $endWeek I get the correct date for that specific calenderweek, but it just does not save it properly.

Can anyone help.


Source: sql

Leave a Reply