2015-10-13 47 views
0

我得到這個:腓的foreach日期

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); 
} 

讓我解釋發生了什麼。 我得到了一個帶有ID,用戶名,calender_week,start_week和end_week的數據庫。

我基本上得到1和52之間的隨機數與該線

$ newcw = mt_rand(1,52);

它代表了日曆周。

接下來的行確實計算了我擁有的每個數字的那一週的開始日期(星期一)和結束日期(星期日)。

接下來我插入並更新我的新值到我的數據庫中。

現在什麼不工作是$startWeek$endweek到我的數據庫更新。

如果我回顯$result_cw_01['calender_week']我得到最後一個用戶的日曆周的$startWeek$endweek

但是,如果我回應$startWeek$endWeek我得到正確的日期爲特定calenderweek,但它只是不能正確保存它。

任何人都可以幫忙。

我改變了更新以選擇和回聲它: $ db-> update($ table,$ set,$ whereWeek,$ valuesWeek);

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

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) 
+0

呼應您以前執行的查詢ANS檢查是如何產生何種查詢。 –

+0

哪些查詢?困惑 –

+0

數據庫查詢... –

回答

0

因爲你不應該使用格式 'Y-d-M',但 'Y-M-d'

+0

這是解決方案的關鍵,我認爲非常感謝 –