I'm trying to get a JSON array from the MySQL database. Here's the part of the code that fetches rows and add them into the array.
<?php
if($rowcount > 0) {
while($row = mysqli_fetch_row($fetch)) {
$row_array["uid"] = $row['unique_id'];
$row_array["users"]["name"] = $row['name'];
$row_array["users"]["email"] = $row['email'];
array_push($users, $row_array);
}
mysqli_free_result($fetch);
echo json_encode($users);
}
?>
This part is causing an error, showing the following message.
Notice: Undefined index: unique_id in /storage/h3/859/644859/public_html/searchfriends.php on line 20
Notice: Undefined index: name in /storage/h3/859/644859/public_html/searchfriends.php on line 21
Notice: Undefined index: email in /storage/h3/859/644859/public_html/searchfriends.php on line 22
Each line represents the following parts.
$row_array["uid"] = $row['unique_id'];
$row_array["users"]["name"] = $row['name'];
$row_array["users"]["email"] = $row['email'];
So, I believe I did not properly format the array. How should I fix it correct?
unique_id,name, andemail. The order is a little bit different though.