<?php
/* Games.php */ 
	$hostname = 'localhost';
	$username = 'narKampen';
	$pass = 'IfRLzj2HJBXA9eei';
	$database = 'narKampen';
	
	$conn = new mysqli($hostname, $username, $pass, $database);
	if (!$conn) {
		die("Connection Failed. ". mysqli_connect_error());
	}
	mysqli_set_charset($conn,'utf8');
	
	$callFunction = $conn->real_escape_string($_POST['f']);
	$userId = $conn->real_escape_string($_POST['userId']);
	
		
	$sql = "SELECT * FROM games WHERE userId = $userId";
	$result = $conn->query($sql);
	if ($result->num_rows > 0) {
		$returnArray = array();
		$data = $result->fetch_assoc();
	    foreach ($data as $key => $value) {
			$returnArray[$key] = $value;
        }
		echo json_encode($returnArray);
	} else {
		echo "No games found for user";
	}
	$conn->close();
	
?>