這是我第一次發佈問題:太多的發佈數據變量?
我正在研究一個WordPress插件,允許用戶在數據庫中創建數據行。當表單有很多(超過100)行數據更新時,我遇到了問題。每行數據包含八個POST數據變量,因此當表單中有100行時,會發送超過800個變量。但是,只有一定數量的變量更新數據庫,現在只有112行更新。我無法弄清楚什麼會阻止函數完成數據庫的更新。它幾乎看起來像我超載後變量太多或發佈數據大小?
一切工作完美與更少的條目,但一旦超過100行,事情停止工作。
這裏是我的表結構:
$sql2 = "CREATE TABLE IF NOT EXISTS $item_table (
id smallint(5) NOT NULL AUTO_INCREMENT,
menu smallint(5) NOT NULL,
itemorder smallint(5) NOT NULL,
item text NOT NULL,
description text,
image tinytext NOT NULL,
value tinytext NOT NULL,
value2 tinytext NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
}
這是帖子的數據處理功能:
foreach($_POST['id'] as $i){
$image = $_POST['image'][$i];
$item = $_POST['item'][$i];
$desc = $_POST['desc'][$i];
$value = $_POST['value'][$i];
$value2 = $_POST['value2'][$i];
$order = $_POST['order'][$i];
if ($_POST['strike'][$i] == 'checked'){
$wpdb->query($wpdb->prepare("DELETE FROM $item_table WHERE id = $i"));
}
else{
$wpdb->update($item_table, array(
'image' => $image,
'item' => $item,
'itemorder' => $order,
'description' => $desc,
'value' => $value,
'value2' => $value2
),
array('id' => $i));
}
}
//Sort items by order, then rewrite the order with no gaps left from deleted items
$targetmenu = $_POST['targetmenu'];
$rows = "SELECT * FROM $item_table WHERE menu = $targetmenu ORDER by itemorder ASC";
$result = $wpdb->get_results($rows);
$n = 1;
foreach ($result as $r){
$id = $r->id;
$wpdb->update($jsrm_item_table , array('itemorder' => $n), array('id' => $id));
++$n;
}
$loc = "&mode=editmenu&targetmenu=".$targetmenu;
header("Location:".JSRM_SELF.$loc);
exit();
}
,這裏是我的PHP形式:
$the_menu = $wpdb->get_row("SELECT * FROM $menu_table WHERE id = $_GET[targetmenu]");
$menuid = $the_menu->id;
$q = "SELECT * FROM $item_table WHERE menu = $menuid ORDER by itemorder ASC";
$result = $wpdb->get_results($q);
if ($result) {
?>
<form id="edit-menu-form" action="<?php echo _SELF; ?>" method="post">
<input type="hidden" name="targetmenu" value="<?php echo $menuid; ?>">
<input type="hidden" name="dbtouch" value="updateitems">
<table>
<?php
foreach ($result as $r) {
$order = $r->itemorder;
$image = $r->image;
$imagesrc = ($image) ? esc_html(stripslashes($r->image)) : 'addimage.jpg';
$item = esc_html(stripslashes($r->item));
$description = esc_html(stripslashes($r->description));
$value = esc_html(stripslashes($r->value));
$value2 = esc_html(stripslashes($r->value2));
$id = $r->id;
?>
<tr id="<?php echo $id ?>">
<td><?php echo $order ?></td>
<td><a class="edit-item-img" id="item-image-<?php echo $id ?>" style="background-image:url(<?php echo $imagesrc ?>);" title="Edit image"></a>
<input type="hidden" name="image[<?php echo $id ?>]" id="field-item-image-<?php echo $id ?>" value="<?php echo $image ?>" />
<img class="remove-image-button" id="image-<?php echo $id ?>" src="removeimage.png"
<?php if(!$image){ ?>
style="visibility:hidden;"
<?php } ?>
/>
</td>
<td><textarea name="item[<?php echo $id ?>]"><?php echo $item ?></textarea></td>
<td><textarea name="desc[<?php echo $id ?>]"><?php echo $description ?></textarea></td>
<td><input type="text" name="value[<?php echo $id ?>]" value="<?php echo $value ?>" /></td>
<td><input type="text" name="value2[<?php echo $id ?>]" value="<?php echo $value2 ?>" /></td>
<td><input type="checkbox" class="strike" name="strike[<?php echo $id ?>]" value="checked"/></td>
<input type="hidden" name="order[<?php echo $id ?>]" value="<?php echo $order ?>" id="order<?php echo $id ?>"/>
<input type="hidden" name="id[<?php echo $id ?>]" value="<?php echo $id ?>" id="id<?php echo $id ?>"/>
</tr>
<?php
}
?>
</table/>
<p><input type="submit" id="update-items-button" value="Update All" class="button-primary"/></p>
</form>
<?php
}
?>