我正在嘗試撰寫一個函式,該函式為每個注冊的新學生回傳一個亂數,但是每次提交表單時,該函式都會回傳一個空值,并且資料庫不接受空值,它應該回傳如下內容: DFA/SSS/22/1246 這是代碼:
function createRegNumber()
{
$schname = "DFA";
$month = date("m");
$year = date("Y");
$new_year = substr($year, 2, 2);
$base_year = 2019; // Set a base when the intakes started
$intake = intval($year) - $base_year; // This will increase for every year
$increase_with = $intake ;
if ($month == '3') {
$intake = $increase_with;
$reg_no = $schname . "/" . $_POST['category'] . "/" . $new_year . "/" . rand(1000, 9999);
} else if ($month == '9') {
$increase_with ;
$intake = $increase_with;
$reg_no = $schname . "/" . $_POST['category'] . "/" . $new_year . "/" . rand(1000, 9999);
}
return $reg_no;
}
uj5u.com熱心網友回復:
看起來問題是你回來了,$reg_no但除非$month == '3'或者$month == '9'它永遠不會被設定。您很可能想要:
if ($month == '3') {
$intake = $increase_with;
} else if ($month == '9') {
$increase_with ;
$intake = $increase_with;
}
$reg_no = $schname . "/" . $_POST['category'] . "/" . $new_year . "/" . rand(1000, 9999);
return $reg_no;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/474881.html
