<?php
include("connect.php");

$result = mysql_query("SELECT poNo FROM purchaseorder ORDER BY poNo DESC LIMIT 1");


$row = mysql_fetch_array($result);
$poNo = $row["poNo"];
list($one[0],$one[1]) = split('PO',$poNo);

$index = ++$one[1];
$num = $index;

if($index < 10)
{
	$index = "PO0000".$index;
}
else if($index < 100)
{
	$index = "PO000".$index;
}
else if ($index < 1000)
{
	$index = "PO00".$index;
}
else if($index < 1000)
{
	$index = "PO0".$index;
}
else if ($index < 10000)
{
	$index = "PO".$index;
}
else
{
	$index = "Purchase Order field is full!";
}

?>