我有一个更新表中字段的方法。它用于更新三个表invoices
invoice_items
和payments
所有三个表都有相同的字段需要更新。当下面的代码运行时,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);
}
}
答案 0 :(得分:1)
对multi_check
的第二次调用将$redirect
参数设置为TRUE
- 因此该函数会重定向,从而阻止脚本第三次调用该函数...