how to make a unique batch number per day?
<p>how to make a batch number per day,
for example, TODAY I manufacture products with no batch:</p>

<ol>
<li>produk A With batch number =>  29092016-1</li>
<li>produk B With batch number =>  29092016-2</li>
<li>produk C With batch number =>  29092016-3</li>
</ol>

<p>TOMORROW no batch should be:</p>

<ol>
<li>produk A With batch number =>  30092016-1</li>
<li>produk B With batch number =>  30092016-2</li>
<li>produk C With batch number =>  30092016-3</li>
</ol>

<p>DAY AFTER TOMORROW no batch should be:</p>

<ol>
<li>produk A With batch number =>  01102016-1</li>
<li>produk B With batch number =>  01102016-2</li>
<li>produk C With batch number =>  01102016-3</li>
</ol>

<p>How do I have to write a code in PHP ??</p>

<p>i have code but no working :</p>

<pre><code>$data_oto     = mysql_fetch_array(mysql_query("select max(id_batch2) as maksi from batch2"));

function buatkode($nomor_terakhir, $kunci, $jumlah_karakter = 0){
$nomor_baru = intval(substr($nomor_terakhir, strlen($kunci))) + 1;
$nomor_baru_plus_nol = str_pad($nomor_baru, $jumlah_karakter, "0", STR_PAD_LEFT);
$kode = $kunci . $nomor_baru_plus_nol;
return $kode;}
$date_now=date('dmY');
$batch=buatkode($data_oto['maksi'],$date_now, 1);

mysql_query("INSERT INTO batch2(id_batch2,id_item) VALUES('$batch','$_POST[item]')");
</code></pre>