<?php
session_start();
ob_start();
include("config/database.php");
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
include "config/function.php";
$take_action1   = new actionDo();
$j				= 1;
$sql_1 			= mysql_query(" select distinct `state` from `tbl_emp_records` where `state`!='Bihar' order by `state` ")or die(mysql_error()); 
//$sql_1 			= mysql_query(" select distinct `state` from `tbl_emp_records` where `state`='Jharkhand' order by `state` ")or die(mysql_error()); 
if(mysql_num_rows($sql_1)>0)
{
	while($data_1	    = mysql_fetch_array($sql_1))
	{
		$i			    = 1;
		$state		    = trim($data_1['state']);
		$sql_2			= mysql_query("SELECT `state_code` FROM `state` where `state_name`='$state' ")or die(mysql_error());
		$data_2			= mysql_fetch_array($sql_2);
		
		$sql_3 			= mysql_query(" SELECT `id` FROM `tbl_emp_records` where `state`='$state' and `status` = '0' order by `id` asc ")or die(mysql_error()); 
		while($data_3	= mysql_fetch_array($sql_3))
		{
			///State Code Make
			if($i<10)
			{
				$state_code	= $data_2['state_code']."-00".$i;
			}
			else if($i<100)
			{
				$state_code	= $data_2['state_code']."-0".$i;
			}
			else if($i>99)
			{
				$state_code	= $data_2['state_code']."-".$i;
			}
			$sql_4 		= mysql_query(" UPDATE `tbl_emp_records` SET `emp_code`='$state_code' where `id`='".$data_3['id']."' ")or die(mysql_error()); 
			$i++;
			$j++;
		}
	}
}

if($i>0)
{
	$_SESSION['msg'] = "Total Records Uploaded : ".($j);
}
else
{
	$_SESSION['msg'] = "Sorry! There is some problem.";
}
echo $_SESSION['msg']
?>