Skip to content
Advertisement

sort details order by user id from another mysql table by activity less than 3600

I wish to fetch all users from “members” table but also check if the member_id from members table and user_id exist in”login” table and then see if column “activity” (current_timestamp) is less than 3600 seconds in login table than order those users on top rest users if don’t exist in login table shows those users in bottom?

how cani query this please.

this is how i fetch users

$query = "SELECT * FROM members WHERE member_id != '".$_SESSION['member_id']."'";

but now how do i query the rest?

really thank you for your help.

Thanks

Advertisement

Answer

You need something like

SELECT members.*
FROM members
JOIN logins ON members.member_id = logins.member_id
WHERE logins.logged_in_at >= CURRENT_TIMESTAMP - INTERVAL 3600 SECOND
-- AND members.member_id != '$_SESSION['tfs_member_id']'

JOIN provides the presence in logins table, WHERE by logged_in_at filters “active” logins.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement