Skip to content

Instantly share code, notes, and snippets.

@Galibri
Created March 6, 2019 20:26
Show Gist options
  • Save Galibri/0956e62fa0ea69a35022492d89974e54 to your computer and use it in GitHub Desktop.
Save Galibri/0956e62fa0ea69a35022492d89974e54 to your computer and use it in GitHub Desktop.
<?php
$year = date('y');
$study_year = $year . ($year + 1);
$dept_code = 123;
$year_code = $study_year . $dept_code;
$student_roll = 1;
$student_roll_full_digit = str_pad($student_roll, 3, "0", STR_PAD_LEFT);
$student_id = $year_code . $student_roll_full_digit;
echo $student_id;
/**
* Mysql code
*/
$year = $_POST['year'];
$dept_code = $_POST['dept_code'];
$query = "SELECT * FROM students WHERE year='' AND dept_code='' ORDER BY id DESC LIMIT 1";
$result = mysqli_query($connection, $query);
$result_exists = mysqli_num_rows($result);
if($result_exists > 0) {
$row = mysqli_fetch_assoc($result) {
$student_id = intval($row['student_id']) + 1;
}
} else {
$student_id = $year . $dept_code . '001';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment