Am I approaching things correctly here? This is what my iOS developer wants me to do for database values for an app he is working on:
{“array”:[{“restID":1, etc.}, {“restID":2, etc.}, {“restID”:3, etc.}, {“restID”:4, etc.}], “error":""}
Right now my PHP code is:
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param("sssisi",$lat,$lat,$lng,$rest_price,$rest_genre,$eat_options);
$stmt->execute();
$stmt->bind_result($rest_id,$user_id,$rest_name,$lat,$lng,$rest_price,$rest_rating,$rest_genre,$eat_options,$result);
//define error array
$errArray = array('error' => '');
while ($stmt->fetch()) {
$row = array(
'restID' => $rest_id,
'userID' => $user_id,
'rest_name' => $rest_name,
'lat' => $lat,
'lng' => $lng,
'restPrice' => $rest_price,
'restRating' => $rest_rating,
'restGenre' => $rest_genre,
'eat_options' => $eat_options);
$rows['array'][] = $row;
}
echo json_encode($rows);
}....
Which outputs the following:
{“array”:[{“restID":1, etc.}, {“restID":2, etc.}, {“restID”:3, etc.}, {“restID”:4, etc.}]}
Notice I can't fit the array in there otherwise I get some crazy stuff or syntax errors with PHP. Please advise! How can I get the first example to work with the current code I am using? What do I need to manipulate in my PHP? Again, I want
{“array”:[{“restID":1, etc.}, {“restID":2, etc.}, {“restID”:3, etc.}, {“restID”:4, etc.}], “error":""}
Not:
{“array”:[{“restID":1, etc.}, {“restID":2, etc.}, {“restID”:3, etc.}, {“restID”:4, etc.}]}