我試圖在數據庫中插入一些序列號。我已經爲此定義了範圍,並且我創建了一個函數,返回最後一條記錄並在已經插入相關序列號時遞增它。但是,當我嘗試增加結果時,代碼中出現錯誤。如果我硬編碼,但不是當我試圖增加值它工作正常:致命錯誤:允許內存大小爲134217728字節耗盡(試圖分配35個字節)
$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;
}
看看你的questio的'Related'權利ñ。 – Rikesh 2013-02-13 07:00:49
增加您分配給PHP的內存大小。 – 2013-02-13 07:01:15
在我看來,你有一種遞歸(在'createColumnsArray'中調用'createColumnsArray'),它是無限的 – k102 2013-02-13 07:02:28