<?php
 
include 'dbconfig.php';
 

 
// Create connection
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
/* grab the posts from the db */
 
$query = "insert into trans1 (no) values(1)";
 

 
$response = mysqli_query($conn, $query) or die('Error query:  '.$query);
 
//$lid = mysqli_insert_id($conn);


$query2="select * from trans1";

$res = mysqli_query($conn, $query2);

$x1=mysqli_num_rows($res);

	$result = array();

//$result["errormsg"]="Success";
$str='000000000';
$pos1=9-strlen(x1);
$pos2='GRN'.substr($str,1,$pos1).$x1;
//echo $pos2.'<br>';
 
//$result["pos"]=$pos2;

	array_push($result,array(
			"pos"=>$pos2,
			"etc"=>"2"
		));
 
if ($response == 1){
 
   // echo json_encode($result);
    	echo json_encode(array('data'=>$result));
 
}
 
else{
 
//    $result["errormsg"]="Fail";
 
    echo json_encode($result);
 
}
 
?>
