I have an 'Android' project where I need to fetch some information from a database. The database is 'MySQL'. I have to go throught a webservice and as I have never done any PHP before now, I hardly see the problem as the logic seems ok to me.
Here is my code:
<?php
require 'connect.php';
$username = 'alex@hotma';
$password = 'soleil';
$sql = 'SELECT ID, NAME, PASSWORD, EMAIL FROM Account';
#$sql = 'CALL Login('.$username .', '. $password .')';
$result = $conn->query($sql);
$response = array();
if (!empty($result))
{
if($result->num_rows > 0)
{
$response['success'] = 1;
$users = array();
while($row = $result->fetch_assoc())
{
$user = array();
$user["id"] = $row["ID"];
$user["name"] = $row["NAME"];
$user["password"] = $row["PASSWORD"];
$user["email"] = $row["EMAIL"];
//Trying to add the user into my users array
//If i uncomment this line everything is shown, but not in the response array
//echo json_encode($user);
array_push($users, $user);
}
$response['users'] = $users;
}
else
{
$response['success'] = 0;
$response['message'] = 'No user found';
}
}
else
{
$response['success'] = 0;
$response['message'] = 'No user found';
}
echo json_encode($response);
$conn->close();
?>
I currently have more than 6 users in my database, but i cannot seems to get them all. I have left some of my code commented so you can see what i have tried, alas without any success. I want to return a 'JSON' array with all my user inside it.
Do any of you have an idea on how to proceed?