0

So I am new to php and json and app development. I tried googling for answers but those answers just generate more errors. I am posting an user_id from the app and trying to get all the gyms related to the users. I have had no problem getting response from other php files.

I am trying to get back a 2d array of 3 columns, gym_id, gym_name, and user_id. The code below results in an error of "Parse error: syntax error, unexpected end of file ... on line 25". I am sorry if this is too amateur, but I simply have ran out of ways to proceed.

Thanks in advance for help.

<?php
    $con = mysqli_connect(...);
    
    $user_id= $_POST["user_id"];
    
    $statement = mysqli_prepare($con, "SELECT Gym.gym_id, Gym.name, user_gym_rel.user_id FROM Gym INNER JOIN user_gym_rel  ON Gym.gym_id = user_gym_rel.gym_id WHERE user_gym_rel.user_id = '$user_id');
    mysqli_stmt_execute($statement);
    

    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $gymid, $gymname, $userid);
    
    $response = array();
    i=0
    while(mysqli_stmt_fetch($statement)){
        $response[i] = array();
        $response[i]['gym_id'] = $gymid;
        $response[i]['gym_name'] = $gymname;
        $response[i]['user_id'] = $userid;
i++;
    }

    echo json_encode($response);

?>

1 Answers1

0

Ok so thanks for the speedy reply, added the ", changed the variable i to $i. and everything works! thanks for the help everyone :)