SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | - | function autono($tabel,$inisial){
|
| 2 | + | function autono($namabarang="barangku"){
|
| 3 | - | $isi=mysql_query("select idbarang from barang order by idbarang desc") or die(mysql_error());
|
| 3 | + | $isi=mysql_query("select count(idbarang) tot from barang ") or die(mysql_error());
|
| 4 | - | $thn=date("Y");
|
| 4 | + | $dt=mysql_fetch_array($isi); |
| 5 | - | if(mysql_num_rows($isi)==0){
|
| 5 | + | $num=$dt['tot']+1; |
| 6 | - | |
| 6 | + | $idbarang=sprintf("%s%05s",
|
| 7 | - | $IDbarang=autono("barang","B$thn");
|
| 7 | + | strtoupper($namabarang)[0], |
| 8 | - | $idbarang="B$thn"."0001"; |
| 8 | + | $num; |
| 9 | - | } |
| 9 | + | return $idbarang; |
| 10 | - | else{
|
| 10 | + | } |