所以我從 json 中獲取一些輸入,即用戶 ID。然后我試圖找到它的朋友和他們的博客以及它各自的評論。顯然,評論將不止一個。因此,每當我將這些評論推送到數組中的一個鍵時,我都會在我的 api 響應中得到空值。我嘗試使用簡單的 $name['comments'] = $res. 但由于會有多個評論,因此它會用舊評論替換新評論。請幫我解決這些問題CoDE-> $userdata = json_decode(file_get_contents('php://input')); $userid = mysqli_real_escape_string($conn, $userdata->userid); // ============================================================================= // ===========================Get Friends======================================= // ============================================================================= $friends = " SELECT `friend_one` FROM `friends` WHERE `friend_two` = '$userid' AND `status` = '1' UNION ALL SELECT `friend_two` FROM `friends` WHERE `friend_one` = '$userid' AND `status` = '1' "; $response = array(); $friendsq = mysqli_query($conn, $friends); if(!$friendsq) { $response['statusCode'] = 400; $response['message'] = "failed to connect to backend. please contact developer"; } $count = mysqli_num_rows($friendsq); // ============================================================================= // ===========================No Friends======================================= // ============================================================================= if($count == 0) { $response['statusCode'] = 202; $response['message'] = "No Friends to show the newsfeed"; } else { $response['statusCode'] = 200; $response['message'] = "Success"; $response['microblogs'] = array(); $name['comments'] = array(); // =============================================================================
添加回答
舉報
0/150
提交
取消