I am trying to take a number of user entries from a SQL database and return it where it will be encoded to JSON and sent back to android.
Currently I am building the part to handle the results from querying the database:
$result = mysql_query("SELECT * FROM users WHERE tower='$tower'") or die(mysql_error());
$resultNo = mysql_num_rows($result);
// check for successful store
if ($result != null) {
//if just one result return it
if ($resultNo == 1) {
// return result
return mysql_fetch_array($result);
//if more than one loop through
} else {
//add each row to an array
while($row = mysql_fetch_array($result)) {
$resultSet[] = $row;
}
return $resultSet[];
} else {
return false;
}
}
The code I am returning to is…
$result = $db->searchForPeople($tower);
Can I return either an array or a single result in this way or should I just add the single result to the array and return that?
Thanks for your help
can this way:
or for example: