<?

Function new_primary_number_readme($s_table, $s_col, $s_fix, $s_sql_extend) {
	//--- Function for get max then plus 1 for new number in primary ---
	//--- Return STRING or NUMBER vary by $s_fix ---
	//--- $s_table = string table where you want ---
	//--- $s_col = string column you want to get max in TB 
	//--- $s_fix = string for format of string number Ex. "0000" (CAN be "" if want to return integer else return string)---
	//--- $s_sql_extend = string for sql statement Ex. "Where province_code = '1234' " (CAN "") ---
    
	include "connect.inc";
	$s_sql = "SELECT MAX($s_col) FROM $s_table $s_sql_extend";
	$result = mysqli_query($conn,$s_sql);
    $row = mysqli_fetch_array($result);
	$i_count = (int)($row[0]) + 1;
    mysqli_close($conn); 
	if ($s_fix == "") {   //--- Return integer
	   return $i_count;    
	} else {               //--- Return string
	   $s_count = $i_count;
	   $s_count = $s_fix.$s_count;
	   $s_count = substr($s_count, strlen($i_count));
	   return $s_count;
	}
}

Function fix_string_readme($s_fix, $s_string) {
	//--- function for fix string in limited format return string Ex. 0000 and 1 => 0001 ---
	//--- $s_fix = string for fix Ex. "0000" or "xxxx") ---
	//--- $s_string = string to change ---
    $i_tmp = -(strlen($s_fix));
	$s_fix = $s_fix.$s_string;
	return substr($s_fix, $i_tmp);

}

?>