<?php 


include("db_connection.php");
$Mainclass=new DB_Controller();

$temp_id = "Temp/0057";


$temp_data = $Mainclass->Fetch_multiple_data("code_test_master","*","Temp_Id='".$temp_id."'");

foreach ($temp_data as $temp_data) {


$data = $Mainclass->Fetch_individual_data("code_test_master","Product_Id","ParentId='".$temp_data['ParentId']."' and Product_Id!='' order by SLN desc limit 1");
$last_product_id = $data['Product_Id'];
$last_product_id_array = explode("-",$last_product_id); 


$newcount = $last_product_id_array[1] + 1;
$newcount_padded = str_pad($newcount, 3, '0', STR_PAD_LEFT);
$Productid = $temp_data['ParentId']."-".$newcount_padded;

$Mainclass->Update_Data("code_test_master","Product_Id='".$Productid."'","SLN='".$temp_data['SLN']."'");	
	
}

?>

