<?php

	print "<table border='1' width='50%' align='center'>";

	print "<tr>
				<td>Sr No</td>
				<td>Member ID</td>
				<td>Payout</td>
			</tr>";

	$db = new PDO('mysql:host=localhost;dbname=mybooster;', 'root', 'root');
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

	$memberIDString ='[
	{
		"MemberID": "816978632"
	},
	{
		"MemberID": "925336111"
	},
	{
		"MemberID": "933783322"
	},
	{
		"MemberID": "211033900"
	},
	{
		"MemberID": "600732476"
	},
	{
		"MemberID": "211037745"
	},
	{
		"MemberID": "724905921"
	},
	{
		"MemberID": "213012867"
	},
	{
		"MemberID": ""
	}
]';
   
    $memberIDIndex = 1;
	$memberIDArray = json_decode($memberIDString);
	//$memberIDArray = $memberIDString;
	
	foreach($memberIDArray as $data)
	{

		$result = payoutInfo($data->MemberID, $db);
		
		echo "<tr>";
		echo "<td>" . $memberIDIndex++  . "</td>";
		echo "<td>" . $data->MemberID . "</td>";
		echo "<td>" . $result . "</td>";
		echo "</tr>";


		

	}



	function payoutInfo($data, $db)
	{
		try{

			$sql = "SELECT sum(incentive) as incentive from my_payout_main where refer_id='$data'";
			//echo $sql . "<br/>";
			$stmt= $db->prepare($sql);
			$stmt->execute();
    		$result = $stmt->fetch(PDO::FETCH_ASSOC);
			return $result['incentive'];
	
		}


		catch(Exception $e)
		{
			$e->getMessage();
			return false;

		}

	}


	


	
?>