0

I am using php to get data form database. It should return three results but it only return one of the results.

How can I fix the problem?

Here is my code:

$statement3 = mysqli_prepare($con, "SELECT * FROM client_ble_gateway WHERE username = ?");

mysqli_stmt_bind_param($statement3, "s", $username);
mysqli_stmt_execute($statement3);
mysqli_stmt_store_result($statement3);
mysqli_stmt_bind_result($statement3, $ble_id, $client_id, $alias, $serial_number, $share_data, $latitude, $longitude,$username);


while(mysqli_stmt_fetch($statement3)){

    $res["ble_id"]=$ble_id;
    $res["alias"]=$alias;
    $res["serial_number"]=$serial_number;
}

$res=array($ble_id, $alias, $serial_number);
echo json_encode($res);

1 Answer 1

2

You have to use multidimensional array to get all data

$result = array();
while(mysqli_stmt_fetch($statement3)){

    $res["ble_id"]=$ble_id;
    $res["alias"]=$alias;
    $res["serial_number"]=$serial_number;
    $result[] = $res;
}
echo json_encode($result);
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.