I just wanted to create sequential ID with suffix and prefix in php. I have done some of the parts but, i need to do that if the id existed in DB variable $i shall be incremented by one to generate the next sequential unique id. I have done this but the ID didn't increment after 2. So any help will be appreciated.
Thank you!
this is the code that check the id exist in the db and generate next unique id number.
for($i = 1 ; $i <= 1000; $i++) {
$formnum = sprintf('%04d', $i);
$id2 = "Prefix".$formnum.date("Y");
$q = "SELECT * FROM table where id='$id2'";
$chk = new DBConnection();
$opchk = $chk->executeQuery($q);
$fetres = mysql_num_rows($opchk);
if( $fetres >0){
$i = $i + 1;
do {
$formnum = sprintf('%04d', $i);
return $formnum ;
}while ($i<=1000);
}else{
return $formnum ;
}
}