never_rain Posted May 4, 2011 Share Posted May 4, 2011 I have a website where users can add their friends. What I am trying to achieve is to show every user that who are their friends that are currently online. If any one knows a link to any script or tutorial that explains this, Please help. Thanks, Faisal Quote Link to comment https://forums.phpfreaks.com/topic/235538-online-friends-script/ Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 How are you storing user attributes? Quote Link to comment https://forums.phpfreaks.com/topic/235538-online-friends-script/#findComment-1210526 Share on other sites More sharing options...
never_rain Posted May 4, 2011 Author Share Posted May 4, 2011 I have a table for the users to store their username password, photo, and some profile detail. Once a user logs in, seperate session is created I believe I have to store that session in a table and once they logout, then I have to delete the session from the table. Does this make any sense ? Quote Link to comment https://forums.phpfreaks.com/topic/235538-online-friends-script/#findComment-1210528 Share on other sites More sharing options...
efficacious Posted May 4, 2011 Share Posted May 4, 2011 well you wouldn't store a session in a table.. you just add: session_start(); to the top of your php docs.. then when you want to log the user out just: session_destroy(); if you want to show them as online you can just put a flag into their row of the DB.. flagging that they are online. remove the flag when they logout Quote Link to comment https://forums.phpfreaks.com/topic/235538-online-friends-script/#findComment-1210530 Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 I would create a db that stores all the friend id's of a given user, using either multiple rows or an array Quote Link to comment https://forums.phpfreaks.com/topic/235538-online-friends-script/#findComment-1210532 Share on other sites More sharing options...
efficacious Posted May 4, 2011 Share Posted May 4, 2011 if you want to record a persons friends you could just one one field of a row called say "friendIDs" or something then just use some special symbol to concatenate them together like "5-3-4-6-7-?..." saving you some space. When you need to use the ID's to pull friend info from the database.. just pull this long string out and break it apart using explode() method.. now you have all your id's in an array to use yay. same thing for the online thing.. just mark the user as online with a flag in the DB under say "online" field w/e , then while your retrieving friend information you can also do a check for which of those friends is online. ' you don't wana get in the habit of making a bunch of different tables in a database for the same thing.. like a user.. just use one table for users giving them each their own row. Quote Link to comment https://forums.phpfreaks.com/topic/235538-online-friends-script/#findComment-1210535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.