我有 2 个 mysql 查询,一个用于获取我所有的朋友,另一个用于获取每个朋友的详细信息和积分总和。
$get_my_friends_query = mysqli_query($GLOBALS['connect'], "SELECT friend_user_id FROM tbl_friend_link WHERE tbl_friend_link.your_user_id = 1");
while($get_my_friends_result = mysqli_fetch_assoc($get_my_friends_query))
{
$get_friend_user_details_query = mysqli_query($GLOBALS['connect'], "SELECT tbl_registered_user.user_id, tbl_registered_user.first_name, tbl_registered_user.last_name, tbl_registered_user.profile_name, SUM(tbl_point.amount) FROM tbl_registered_user JOIN tbl_point ON tbl_registered_user.user_id = tbl_point.user_id WHERE tbl_registered_user.status = 1 AND tbl_registered_user.user_id = '" . $get_my_friends_result['friend_user_id'] ."' GROUP BY tbl_registered_user.user_id ORDER BY SUM(tbl_point.amount)");
$get_friend_user_details_result = mysqli_fetch_assoc($get_friend_user_details_query);
$result = array(
"done" => "true",
"name" => $get_friend_user_details_result['first_name'] . " " . $get_friend_user_details_result['last_name'],
"profile_name" => $get_friend_user_details_result['profile_name'],
"userID" => $get_friend_user_details_result['user_id'],
"points" => $get_friend_user_details_result['SUM(tbl_point.amount)'],
"number_friends" => mysqli_num_rows($get_my_friends_query),
"error_message" => ""
);
$row_array[] = $result;
}
echo json_encode($row_array);
我正在使用第一个查询,因为我希望显示结果,无论它们是否有任何点。我想根据点的总和对结果进行排序,但是在第二个查询中正在检索信息,但是我找不到关于如何在 $row_array 上使用 usort 的合适解释。