<?php $_REQUEST['src']='ext';require_once('global.php');
$_REQUEST['clientnumber']=1665;
//CHECK NUMBERING
$stmt = $GLOBALS['con']->prepare("SELECT `no` FROM `writtenscheme` WHERE `clientnumber`='".$_REQUEST['clientnumber']."'")or die(mysqli_error($e="CHECK WS NO: ".$GLOBALS['con']));
$stmt->execute();$s=$stmt->get_result();$stmt->close();
$number_array=array();
while($n=mysqli_fetch_array($s)){
$d=explode(":",$n['no']);
$number=str_replace('WS','',$d[0]);
if($number!="00"){$number_array[]=$number;}
}

//$n = sprintf('%02d',$n);
//$wsn="WS".$n;
$current= max($number_array);
$new=$current+1;
$n = sprintf('%02d',$new);
$wsn="WS".$n;

echo $wsn;