<?php 
    ###### GENERATE CODE ######
    $year=date('Y');
    $this_Yr =  substr($year,2,2);
    $mon = date('m');
    $dy = date('d');
    
    $perfix='ENGR/';
    // SELECT HELP TO SELECT LAST ORDER NO
    $newcode = $db->prepare('select codeproj from tbl_projects ORDER BY projid DESC LIMIT 1');
    $newcode->execute();
    $rowcount11 = $newcode->rowCount();
    if($rowcount11 > 0)// if there is data for that reg. number...
    {
    $row1 = $newcode->fetch();
    $PNo = $row1['codeproj'];
    $new1 = substr("$PNo", 11); 
    $yr = substr("$PNo", 5,2);    
    
    if($yr == $this_Yr){
    $po=str_pad($new1+1,4,"0",STR_PAD_LEFT);     
    }else{$po = "0001";}
    
    }else{$po = "0001";}
    
    ####### END COUNT ######
    $uniqueNo = $perfix.$this_Yr.$mon.$dy.$po; 
?>