0

If i want to call an array from php into typescript also in an array form how i can do it this is my php code :

$AccessQuery = "SELECT name,lastname,phone,email
                      FROM user
                     INNER JOIN access ON id

                     WHERE id 
$userQuery = mysqli_query($localhost, $AccessQuery) or trigger_error(mysql_error(), E_USER_ERROR);
while ($AccessQueryRow = mysqli_fetch_assoc($userQuery)) {
    $AccessData[] = array(
        'id' => $AccessQueryRow['id'],
        'code' => $AccessQueryRow['code'],

    );
};

$arr = array(

    "user_access_details" => $AccessData,

);
echo json_encode($arr);

I try this in order to encoded and use each one as a variable in an array

 var jsonData = JSON.parse(data);

what i really want is how i can put each menu_id in an array field : arr= {id1,id2} the same for the code

3
  • 1
    eh, you have a syntax error and your query looks to be missing something Commented Jul 11, 2016 at 6:33
  • Please take the time to format your post correctly to make it easier or us to help you. Commented Jul 11, 2016 at 6:33
  • but my work work fine and give the result i need what i relay need is how i call this array " $AccessData[] " into my app in form of array in order to fetch all data into this array Commented Jul 11, 2016 at 6:45

1 Answer 1

1

how i can put each menu_id in an array field : arr= {id1,id2}

If you only care about the ids, ignore the code values. Get the array of the shape you want in PHP.

while ($AccessQueryRow = mysqli_fetch_assoc($userQuery)) {
    $AccessData[] = $AccessQueryRow['id'];
};

echo json_encode($AccessData);

On the client side:

var jsonData = JSON.parse(data);

The result will be the array of just ids.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.