我正在尝试将一些序列号插入数据库。我已经为此定义了范围,并且我创建了一个函数,它返回最后一条记录,如果我已插入相关的序列号,则递增它。但是,当我尝试递增结果时,我在代码中收到错误。如果我硬编码它可以正常工作,但是当我尝试增加值时它没有工作:
$batch = $_POST['batch'];
$serial=11111111;
if(array_key_exists('batch',$_POST)){
$query="select serial from serials where serial like";
$query.="'".$_POST['batch']."%'";
$query.='order by serial DESC limit 0,1';
$rs=mysql_query($query);
while($row= mysql_fetch_assoc($rs)){
$a =($row[serial]);
$a = substr($a,0,2);// substring to match the string
if($a == $batch){
$a2 =($row[serial]);
$a2 = substr($a2,2,-1);//substring to get the serial
$serial =$a2;
}
else
{
$serial=11111111;
};
}
}
function createColumnsArray($end_column, $first_letters = ''){
$columns = array();
$length = strlen($v);
$letters = range($serial,11111999); //(12847017, 12847027);
foreach ($letters as $letter){
$column = $first_letters.$_POST['batch'].$letter.'Z';
$columns[].=$column;
if ($column == $end_column)
return $columns;
}
foreach ($columns as $column){
if (!in_array($end_column, $columns) && strlen($column) < $length) {
$new_columns = createColumnsArray($end_column, $column);
// Merge the new columns which were created with the final columns array.
$columns = array_merge($columns, $new_columns);
}
}
return $columns;
}
答案 0 :(得分:1)
这是因为你的内存限制尝试
ini_set('memory_limit', '256M');
134217728字节= 128 MB
或者考虑重写一个有效的代码,以便它消耗更少的内存..
答案 1 :(得分:0)
Try...
Allowed memory size maximum. Put the code top of the file
ini_set('memory_limit', '-1');