Good evening everyone, until a few days ago I had never used PHP or JSON and I am finding trouble getting multiple rows from phpmyadmin to Java using JSON. I have manged to write the below code however this only gets the last row.
I took a look at this post (how to encode multiple rows from mysql into json using php) and had a go but have had no luck..
<?php
$user = 'root';
$pass = '';
$db = 'uopuser';
$con=mysqli_connect('localhost', $user, $pass, $db) or die('Unable to connect');
$statement = mysqli_prepare($con, 'SELECT * FROM society');
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $society_id, $name, $email, $description);
$society = array();
while(mysqli_stmt_fetch($statement)){
$society['society_id'] = $society_id;
$society['name'] = $name;
$society['email'] = $email;
$society['description'] = $description;
}
echo json_encode($society);
mysqli_stmt_close($statement);
mysqli_close($con);
?>
Thank you in advance!