SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | - | function auto_number($field,$table,$key,$Parse,$Digit_Count){
|
| 3 | + | function auto_number($field,$table,$key,$Parse,$Digit_Count=4){
|
| 4 | - | $NOL="0"; |
| 4 | + | $NOL="0"; // apa ini?? |
| 5 | - | $sql = mysql_query("Select $field from $table where $key like '$Parse%' order by $key DESC");
|
| 5 | + | $sql="Select |
| 6 | - | $counter=2; |
| 6 | + | $field from |
| 7 | - | if(mysql_num_rows($sql)==0) |
| 7 | + | $table |
| 8 | - | {
|
| 8 | + | where $key like '$Parse%' |
| 9 | - | while($counter < $Digit_Count) |
| 9 | + | order by $key DESC"; |
| 10 | - | {
|
| 10 | + | /* |
| 11 | - | $NOL="0".$this->NOL; |
| 11 | + | Menemukan tabel dengan kata kunci tertentu, table tertentu |
| 12 | - | $counter++; |
| 12 | + | dan parsenya sudah ditentukan |
| 13 | field=pos | |
| 14 | - | return $Parse.$this->NOL."1"; |
| 14 | + | table=siswa |
| 15 | key=code | |
| 16 | - | else |
| 16 | + | parse=IT |
| 17 | - | {
|
| 17 | + | digit_count=jumlah digit.. biasanya 4 |
| 18 | - | $R = mysql_fetch_array($sql); |
| 18 | + | sebenarnya kalau dipikir-pikir.. lebih baik fied dan key |
| 19 | - | $K = sprintf("%d",substr($R[0],-$Digit_Count));
|
| 19 | + | digabung?!? |
| 20 | - | $K = $K + 1; |
| 20 | + | */ |
| 21 | - | $L = $K; |
| 21 | + | $q = mysql_query($sql); |
| 22 | - | while(strlen($L)!=$Digit_Count) |
| 22 | + | // $counter=2; jumlah 0 tapi ini gk efektif |
| 23 | - | {
|
| 23 | + | |
| 24 | - | $L = $NOL.$L; |
| 24 | + | if(mysql_num_rows($q)==0) |
| 25 | {
| |
| 26 | /* | |
| 27 | - | return $Parse.$L; |
| 27 | + | Ternyata ngak ada / tidak ditemukan datanya |
| 28 | yang sesuai pencarian. Maka nilainya 1 | |
| 29 | tetapi ada digitnya | |
| 30 | while($counter < $Digit_Count) | |
| 31 | {
| |
| 32 | $NOL="0".$this->NOL; | |
| 33 | $counter++; | |
| 34 | } | |
| 35 | Ada cara terbaik tetapi karena menghormati logicmu.. | |
| 36 | jadi tetap digunakan | |
| 37 | */ | |
| 38 | while($counter < $Digit_Count) | |
| 39 | {
| |
| 40 | $NOL="0".$NOL; | |
| 41 | $counter++; | |
| 42 | } | |
| 43 | ||
| 44 | return $Parse.$NOL."1"; | |
| 45 | ||
| 46 | } | |
| 47 | else | |
| 48 | {
| |
| 49 | ||
| 50 | $R = mysql_fetch_array($q); | |
| 51 | /*jumlah data yang sesuai pencarian*/ | |
| 52 | /* | |
| 53 | $K = sprintf("%d",substr($R[0],-$Digit_Count));
| |
| 54 | ||
| 55 | bila kamu memakai logic while di atas.. ada bagusnya | |
| 56 | memakai konsep yang sama juga.. walau beda tetapi untuk | |
| 57 | keseimbangan kode | |
| 58 | konsepnya sama.. ini buat mendapatkan angka terakhir | |
| 59 | kurang efektif krn membingungkan jadi harusnya | |
| 60 | dan tambahkan 1 krn ingin mendapatkan 1 | |
| 61 | */ | |
| 62 | $K=intval($R[0])+1; | |
| 63 | //$K = $K + 1; | |
| 64 | $L = $K; | |
| 65 | ||
| 66 | while(strlen($L)!=$Digit_Count) | |
| 67 | {
| |
| 68 | $L = $NOL.$L; | |
| 69 | } | |
| 70 | /* Membuat digit 0 */ | |
| 71 | ||
| 72 | return $Parse.$L; | |
| 73 | } | |
| 74 | ||
| 75 | } | |
| 76 | ||
| 77 | ||
| 78 | echo auto_number('nis','mahasiswa','nis',$kdFakultas.$kdJurusan.$thnMasuk,$jmlUrut);
| |
| 79 | ||
| 80 | ?> |