2017-02-10 93 views
0

我有一個方法更新表中的字段。它用於更新三個表,invoicesinvoice_itemspayments所有三個表有相同的字段進行更新。當下面的代碼運行時,multi_checked()方法運行前兩次,但不是第三次運行,對於我而言,這並不明顯。有任何想法嗎?方法不被稱爲第三次

方法調用:

elseif (isset($_POST[$mod . '-del']) && count($check) > 0) { 
    $state = multi_checked(
     $check, 
     'UPDATE ' . $db['database'] . '.invoices SET deleted="Y"', 
     EVENT_DEL, 
     'Invoice [' . $c . '] deleted', 
     'Please select at least one item', 
     FALSE, 
     'SELECT id FROM ' . $db['database'] . '.invoices' 
    ); 
    $state = multi_checked(
     $check, 
     'UPDATE ' . $db['database'] . '.payments SET deleted="Y"', 
     EVENT_DEL, 
     'Payment [' . $c . '] deleted', 
     'Please select at least one item', 
     TRUE, 
     'SELECT id FROM ' . $db['database'] . '.payments', 
     null, 
     "id_invoice" 
    ); 
    $state = multi_checked(
     $check, 
     'UPDATE ' . $db['database'] . '.invoice_items SET deleted="Y"', 
     EVENT_DEL, 
     'Invoice Item [' . $c . '] deleted', 
     'Please select at least one item', 
     TRUE, 
     'SELECT id FROM ' . $db['database'] . '.invoice_items', 
     null, 
     "id_invoice" 
    ); 


} # Clear Export timestamps 

multi_checked方法被描述如下:

function multi_checked(
    $check, 
    $query, 
    $event_type, 
    $event_desc, 
    $none = 'Please select at least one item', 
    $redirect = TRUE, 
    $meta_query = NULL, 
    $success_msg = NULL, 
    $field = "id" 
) { 
    global $db, $mod; 

    $batch_count = count($check); 
    $meta_data = NULL; 

    if ($batch_count == 0) { 
     add_msg($none); 
     return (0); 
    } else { 
     $changed = 0; 
     $ref = load_array('SELECT MAX(id) FROM ' . $db['database'] . '.eventlog'); # batch id 
     foreach ($check As $c) { 
      if ($meta_query != NULL) { 
       $meta_data = load_array($meta_query . ' WHERE id' . $field . '="' . $c . '"'); 
       if ($meta_data != NULL) $meta_data = ' (' . $meta_data . ')'; 
      } 
      $q = $query . ' WHERE ' . $field . '="' . $c . '"'; 
      $z = $query . ' WHERE ' . $field . '="' . $c . '"'; 
      $g = "asf"; 
      if (run_query($query . ' WHERE ' . $field . '="' . $c . '"') == 0) { 
       eventlog($db['database'], $event_type, $mod, $c, uid(), '[Batch #' . $ref . '] ' . $event_desc . $meta_data, uname()); 
       $changed++; 
      } else { 
       eventlog($db['database'], $event_type, $mod, $c, uid(), '[Batch #' . $ref . '] FAIL: ' . $event_desc . $meta_data, uname(), FALSE, FALSE); 
      } 
     } 
     # Check for errors 
     if ($changed != $batch_count) { 
      add_error($changed . ' of ' . $batch_count . ' items processed - you may need to check the system log for details'); 
     } # Success! 
     else { 
      $message = ($changed . ' item' . ($changed > 1 ? 's' : NULL) . ' processed successfully'); 
      if ($changed > 1) { # log batch summary 
       @mysql_query("FLUSH QUERY CACHE"); 
       eventlog($db['database'], $event_type, $mod, 0, uid(), '[Batch #' . $ref . '] ' . $changed . ' records processed', uname()); 
      } 
      # Redirect 
      if ($redirect) { 
       header('Location: ?m=' . $mod . '&changed=' . $changed . '&message=' . $success_msg); 
       exit; 
      } else { 
       add_msg($message); 
      } 
     } 
     return ($changed); 
    } 
} 

回答

1

multi_check第二呼叫已$redirect參數設置爲TRUE - 這樣的函數重定向,防止腳本第三次撥打該功能...