これが私のコードです:
$result = mysqli_query($dbconnection, Data::followUser($user_id, $followUser_id));
$result
ここでは空を返します。
followUser
クラスのメソッドData
public static function followUser($user_id, $followUser_id) {
global $database;
$query = "
SELECT *
FROM profile_follow
WHERE user_id = '{$user_id}'
AND follow_id = '{$followUser_id}';";
$result = $database -> query($query);
$num = mysqli_num_rows($result);
if ($num < 1) {
$toast = "Follow";
$query = "
INSERT INTO profile_follow (user_id, follow_id)
VALUES ('{$user_id}', '{$followUser_id}');";
$result = $database -> query($query);
} elseif ($num > 0) {
$toast = "Unfollow";
$query = "
DELETE FROM profile_follow
WHERE user_id = '{$user_id}'
AND follow_id = '{$followUser_id}';";
$result = $database -> query($query);
}
return $toast;
}
$toast をエコーアウトする際に、関数が正しく動作することを確認しました。またはFollow
条件Unfollow
による。それが出てきたとき、私はそれを正しく扱っているとは思いませんか?
補足:
これが私が $result でやっていることです:
if ($result == "Follow") {
$output["result"] = "Follow";
echo json_encode($output);
} elseif ($result == "Unfollow") {
$output["result"] = "Unfollow";
echo json_encode($output);
}