$sql="SELECT po FROM po order by id desc";
$result=mysql_query($sql);
$rowSe=mysql_fetch_array($result);
$newpo=$rowSe['po'];
if($newpo=="") $npo="PO0001";
else {
$newpo=substr($newpo,2,5);
$num=$newpo+1;
$digitnum=strlen($num);
switch($digitnum) {
case 1: $npo="PO000$num";break;
case 2: $npo="PO00$num";break;
case 3: $npo="PO0$num";break;
case 4: $npo="PO$num";break;
}
}
$sql_in="INSERT INTO po (po) VALUES ('$npo')";
$result_in=mysql_query($sql_in);
$po=$npo;
echo $po;
?>