使用PHP CodeIgniter对数组推送进行排队
我在同时使用2个阵列推送时遇到问题。当我在第一个数组中放入10个元素,在第二个数组中放入20个元素时,效果很好。但当我在第一个数组上按1000个元素时,第二个数组不会按使用PHP CodeIgniter对数组推送进行排队,php,arrays,codeigniter,Php,Arrays,Codeigniter,我在同时使用2个阵列推送时遇到问题。当我在第一个数组中放入10个元素,在第二个数组中放入20个元素时,效果很好。但当我在第一个数组上按1000个元素时,第二个数组不会按 这是我的密码: public function save() { extract($_POST); $first_array = array(); $second_array = array(); // This array contains 1000 elements to push for
这是我的密码:
public function save() {
extract($_POST);
$first_array = array();
$second_array = array();
// This array contains 1000 elements to push
foreach($data as $key) {
$data3 = array(
'LOCATION_ID' => $key,
'TRX_ID' => $id,
);
array_push($first_array,$data3);
}
// This array contains 20 data
for($i = 0; $i < $total ; $i++) {
$data4 = array(
'CONDITION' => $CONDITION[$i],
'TRX_ID' => $id
);
array_push($second_array,$data4);
}
$insert_first = $this->db->insert_batch('LOCATION',$first_array);
$insert_second = $this->db->insert_batch('CONDITION',$second_array);
if($insert_first) {
if($insert_second) {
$message = array(true,'success');
} else {
$message = array(false,'failed');
}
} else {
$message = array(false,'failed');
}
echo json_encode($message);
}
public函数保存(){
摘录(元);;
$first_array=array();
$second_array=array();
//此数组包含1000个要推送的元素
foreach($数据作为$key){
$data3=数组(
'LOCATION_ID'=>$key,
'TRX_ID'=>$ID,
);
数组推送($first\u数组,$data3);
}
//此数组包含20个数据
对于($i=0;$i<$total;$i++){
$data4=数组(
“条件”=>$CONDITION[$i],
'TRX_ID'=>$ID
);
数组推送($second\u数组,$data4);
}
$insert_first=$this->db->insert_批('LOCATION',$first_数组);
$insert\u second=$this->db->insert\u batch('CONDITION',$second\u array);
如果($insert_first){
如果($insert_second){
$message=array(true,'success');
}否则{
$message=array(false,'failed');
}
}否则{
$message=array(false,'failed');
}
echo json_编码($message);
}
PHP,因为版本5.3.9有一个很好的小特性,它限制了POST
请求的大小(以输入变量的数量衡量),默认值为1000。PHP(以及codeigniter)忽略的任何以上内容
如果您需要发布1000多个变量(或者认为您将来可能需要发布),则需要在php.ini
中更改max\u input\u vars
变量的值。就像我说的,默认值是1000,所以根据需要更改它
即使在5.3.9以上的PHP版本上,您也可能会发现max\u input\u vars
指令在PHP.ini
上找不到。不要被它不存在的事实误导,因为它将默认为1000。只需创建它:)控制第二个循环集的$total
在哪里?$total来自视图,从extract($\u POST)提取,还有$id…@Nigelrenco这是内存问题吗?有时候PHP会默默地失败。这是我不会想到的另一个问题@JohannesSchidlowski@BaktiWijaya其中是$id
、$total
和$CONDITION
?
<form method="POST" action="<?php echo base_url()?>admin/transaction/save">
<div class="form-group">
<label>Location</label>
<select name="LOCATION[]" multiple class="form-control">
<?php foreach($LOC as $key) : ?>
<option value="<?php echo $key['id_location'] ?>"><?php echo $key['location_name'] ?></option>
<?php endforeach; ?>
</select>
</div>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="hidden" name="total" value="<?php echo count($CON); ?>">
<div>
<table>
<thead>
<tr>
<th>#</th>
<th>NAME</th>
<th>VALUE</th>
</tr>
<thead>
<tbody>
<?php $no = 1; foreach($CON as $value) : ?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $value['condition_name'] ?></td>
<td><input type="number" name="CONDITION<?php echo $no; ?>"></td>
</tr>
<?php $no++ ;endforeach; ?>
</tbody>
</table>
</div>
</form>