Last active
November 11, 2015 09:35
-
-
Save hendrasyp/b60477755dbef5acae25 to your computer and use it in GitHub Desktop.
Function to generate Format autonumber using CodeIgniter and YII Frameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _autonumber($field, $table, $Parse, $Digit_Count) { | |
$NOL = "0"; | |
$query = "Select " . $field . " from " . $table . " where " . $field . " like '" . $Parse . "%' order by " . $field . " DESC LIMIT 0,1"; | |
// CODEIGNITER | |
$identifier = &get_instance(); | |
$data = $identifier->db->query($query)->result_array(); | |
// YII Way | |
// $identifier = \Yii::$app->db; | |
// $data = $identifier->createCommand($query)->queryOne(); | |
$counter = 2; | |
if (sizeof($data) == 0) | |
{ | |
while ($counter < $Digit_Count): | |
$NOL = "0" . $NOL; | |
$counter++; | |
endwhile; | |
return $Parse . $NOL . "1"; | |
} | |
else | |
{ | |
//CODE IGNITER | |
$R = $data[0][$field]; | |
// YII | |
// $R = $data[$field]; | |
$K = sprintf("%d", substr($R, -$Digit_Count)); | |
$K = $K + 1; | |
$L = $K; | |
while (strlen($L) != $Digit_Count) | |
{ | |
$L = $NOL . $L; | |
} | |
return $Parse . $L; | |
} | |
} // end of function | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment