I'm trying to return the array of rows where the username matches the username in the database table. The JSON result just gives me the last row.
example table:
james 14 u@aol.com
mah 12 j@aol.com
james 23 ra@yahoo.com
result gives me:
23 ra@yahoo.com
but i want both james rows not just the last one. so both 14 u@aol.com and 23 ra@yahoo.com thanks
My php code:
<?php
$username = $_POST["username"];
$con = new mysqli("xx", "xx", "xx", "xx");
// selects everything
$statement = mysqli_prepare($con, "SELECT * FROM `user` WHERE username = ?");
mysqli_stmt_bind_param($statement, "s", $username);
mysqli_stmt_execute($statement);
// Store the result to use
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $id, $username, $age, $email);
// Get results returned and put in array
$user = array();
while (mysqli_stmt_fetch($statement)) {
$user[age] = $age;
$user[email] = $email;
}
// Send array back to phone
print (json_encode($user));
mysqli_stmt_close($statement);
mysqli_close($con);
?>