PHP - Online Friends Script
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 Similar TutorialsI have two button that load the next and previous pages of friends, I'm having trouble doing so, it sort of works, but it's got bugs so it's not right. Next: Code: [Select] $query = mysql_query("SELECT * FROM friends WHERE (friend_1='".$id."' OR friend_2='".$id."') AND id>$last_id ORDER BY id ASC LIMIT 16");previous: Code: [Select] $query = mysql_query("SELECT * FROM friends WHERE (friend_1='".$id."' OR friend_2='".$id."') AND id<$last_id ORDER BY id ASC LIMIT 16"); $id = id of the users profile. $last_id = the last loaded friend id (unique id to friends table , not the friends actual id) I looked for a script that shows the number of users online on the site i am making, and found this. I don't know if it is for just showing if the user is online on that one page like a profile page, or if it is for all users in the database. Also, when using the code, it shows "Users Online: 1" then when I reload the page, it says "2' and again, then "3" even though no users have logged in. Thank you. the script Code: [Select] <?php ///////////////////////////////////////////////////////////////////////////////////////// ////IS USER ONLINE SCRIPT PART//// $session=session_id(); $time=time(); $time_check=$time-600; //SET TIME 10 Minute //CONNECT TO DB //connect info here // Connect to server and select databse mysql_connect("$host1", "$username1", "$password1")or die("cannot connect to server"); mysql_select_db("$db_name1")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name1 WHERE session='$session'"; $result=mysql_query($sql)or die(mysql_error()); $count=mysql_num_rows($result); if($count=="0"){ $sql1="INSERT INTO $tbl_name1(session, time)VALUES('$session', '$time')"; $result1=mysql_query($sql1)or die(mysql_error()); } else { "$sql2=UPDATE $tbl_name1 SET time='$time' WHERE session = '$session'"; $result2=mysql_query($sql2)or die(mysql_error()); } $sql3="SELECT * FROM $tbl_name1"; $result3=mysql_query($sql3)or die(mysql_error()); $count_user_online=mysql_num_rows($result3); echo "User online : $count_user_online "; // if over 10 minute, delete session $sql4="DELETE FROM $tbl_name WHERE time<$time_check"; $result4=mysql_query($sql4); mysql_close(); // Open multiple browser page for result ///////////////////////////////////////////////////////////////////////////////////////////// ?> Hey everyone, I'm currently working on a friends online script and i have a slight problem that i need help with. Basically the code first searches "TBL_Friends" to see if you have any friends added. If it returns results it then turns your friends ID's into a variable. It then searches "TBL_Users_Online" to see if any body is logged based on the friend's ID it returned before. The first bit of the code works and it retrieves all the friends i got added. The second half is odd, if i have one or two friends added it will show that one is online. If i have more then three friends added it returns no results. I know my code is a bit sloppy and probably not the best way of writing it, im still learning PHP. Anyways this is the code, any help is appreciated. Code: [Select] <?php $FriendsOnline = mysql_query("SELECT Sender_ID FROM TBL_User_Friends WHERE Reciever_ID = $UserID"); while($fo=mysql_fetch_array($FriendsOnline)) { $FriendsOnlineID = $fo[Sender_ID]; $FriendsOnlineNumber = mysql_query("SELECT * FROM TBL_Users_Online WHERE User_ID = $FriendsOnlineID"); $FriendsNumber = mysql_num_rows($FriendsOnlineNumber); echo $FriendsNumber; } ?> $SenderID = Friends ID $Reciever_ID = User ID $UserID = User ID Hi, I just want to see what way you guys think is best. On this little community I'm building I have decided to implement a function to see who were active within the last 15 minutes. I made a table (just user and timestamp) to register the last activity of any logged on user. Then I have a variable to take off 15 minutes from that but I can't get them to compare. Googling the issue I found people are solving this in very different ways. I wanted to see what phpfreaks recommend as the next step. Here is some code (that doesn't work properly - no results found as I compare to different timestamps): Code: [Select] include_once'header.php'; $now=time(); $now=(date("Y-m-d H:i:s")); //$mins = mktime(0,$now-15,0, date("Y"), date("m"),date("d")); $mins = time(); $mins15 = $mins-(60*15); $mins15 = (date("Y-m-d H:i:s", $mins15)); $online="SELECT * FROM user_online" WHERE last_activity > mins15; $result = mysql_query($online); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); echo <<< _END <div id='statusbar'> <h4>Online now: $rows</h4> I've been looking for a simple script that would connect to a game server to see if it is still online. I've found many, but not one of them work. They will permanently send back the text "Online", or "Offline". This is the simplest code I have found: <?php $ip = "66.79.190.40"; $port = "27960"; if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) echo '<B><FONT COLOR=red>Offline</b></FONT>'; else{ echo '<B><FONT COLOR=lime>Online</b></FONT>'; fclose($sock); } ?> I'm also looking into getting it to pull the map name and player-list, but I should be able to figure that out on my own once I get this working. If it helps, this script is supposed to connect to the original Quake games(One, two, and three). I almost posted this in the freelancing forum, because I am looking for it to be created, but I first needed more info on what a coder would need to know about the project. I have a script that is designed for a single person, and I want a coder to design it to become an online service with user registration, etc. I'm weary of posting publicly the details about what the script does, but is something like that needed in order for a php programmer to take on a job? Could something like that be left out, until actually giving the coder the job? Do I have to give at least a vague idea of what the script does? I don't understand enough about what a programmer would need to know, but at the same time, I don't want to reveal my idea either. Can somebody help me on how much I am going to need to reveal? Thanks. Table friends users Fred Tom Julie Henry Bill Wally Joe Joe friendwith Joe Joe Joe Joe Joe Joe Julie Wally Fred, Tom, Julie, Henry, Bill, and Wally have friended Joe. Code: [Select] <?php $username = 'Joe'; $query = "SELECT * FROM friends WHERE friendwith=' $username'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['users']."<br/>"; echo $row['friendwith']."<br/>"; } ?> Joe is friends with Julie and Wally. Code: [Select] <?php $username = 'Joe'; $query = "SELECT * FROM friends WHERE users='$username'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['users']."<br/>"; echo $row['friendwith']."<br/>"; } ?> Here's where I need your expert advice! I want to know who friended Joe except for those that Joe has friended. In other words, I want to show Fred, Tom, Henry, and Bill. Julie and Wally should not be included in the query because Joe has friended them as well. Hi guys, im making a basic social networking site for a college project and I need to know how to make a system that will let logged in users add each other as friends but I carnt really find anything on google about how to start. Can anyone here help me or know a tutorial I can follow that will let me create something like this? Thanks Say i was going to store a "friends list" for a user. Would it be easier to store the names in a text string in the db instead of having to make a new field for each friend? In other words: 001 | Keith | Joe, Jane, Mike or 001 | Keith | Joe | Jane | Mike It seems like a pain to make a column for each but since i'm only 6 months into php i haven't really tapped into it's ability to deal with a string of data. My end game would to at some point take the user list and make a selectable table: Friends: Joe Jane Mike Preferably with an array pseudo coded as: Count how many users for each user echo username <a href username's page> Bottom line: Store as Columns or String? p.s. i've reviewed php.net etc. so it's not a matter of not knowing how but more which is preferable Hi guys, I'm developing a website which allows people to connect and follow each other's activity (like Twitter, for example). To simplify everything, let's say I only have 2 tables: 1. Followers id | follower_id | id_to_follow ------------------------------------ 2. Activity id | member_id | message | time ----------------------------------------- Let's say John is following Jane and Bob. I want to create a "news" page and display the last 20 messages from Bob and Jane, chronologically. For small numbers, I'd do something like this: Select everything from the Activity table, check for every entry if the member is a friend of John's (in the Followers table) and, if so, display the message, ORDER BY `id` DESC. But, this is very inefficient, I guess, for larger numbers (I can't even think about how many queries would take to do this on a site like Twitter...). Any ideas of how to do the same thing more efficiently? Thank you. I have just a general question about a friends system here with regards to the database design....... lets say you have a website where users can rent books. The database design would be MEMBER BOOK LINk memberid isbn memberid name name isbn Or something to that extent Now with a friends system like facebook has that "LINK" table would be absolutley huge and I cant see it being good design practise. I mean how do you suppose facebook does this. Do they have ...... FRIENDS myID friendID and just millions upon millions of repeated data? The only way I can see would be in the member table have a field called friends and then the ID's of each friend like so Friends 001, 002, 003, 004, 005, 006, 007, Now is my logic correct here or am I thinking of this totally the wrong way? Would the other way be a better option or would it take the system too long to get to the 1000,000 th record in the database? I believe the first option would be correct but I cant see how the server would handle the request if say you had 1000,000 users. It just seems to me that you would create too many records. In my website people can sign up to mulitple events but if every user had 100 events the link table would just be massive!!!!!!!!!!!!!!!!!!!!!! Im just after peoples input really on the situation. Thank you I'm trying to make it so i can show the friends i added, or users that added a friend <table border=2 width="250" height="125"><tr> <?php $userfinal = get_username($_SESSION['user_id']); $Members = mysql_query("SELECT * FROM friends WHERE username='$userfinal' AND friendname"); $numRowsMembers = mysql_num_rows($Members); for($count = 1; $count <= $numRowsMembers; $count++) { $name = mysql_fetch_array($Members); ?> <td width="150" height="125"> <a href="view_profile.php?username=<? echo $name['friendname']?>"><img src="<? echo $name['main_P']?>" width="100" height="100"/> <? echo $name['friendname']?></a> <? if (isset($name['date']) && (time() - $name['date'] > 300)) { echo 'offline =['; } else { echo "<font color=green>[Online Now!]</font>"; } $name['date'] = time(); // update last activity time stamp ?> </td> <? } ?> </tr></table> database id friendname username 12 kristybellexo zhshero 13 demo zhshero 14 zhshero zhshero I have a database with all users.. Within that database all users have an id. How would I make it so users can "friend" other users? Would I need to make a new table for that? Im sorry for the dumb question.. I havent dealt with php or mysql in about two years because I was busy getting engaged and all.. But now that I have time again I think im gonna take up one of my old projects. Granted I probably could have answered this question myself back then but now im finding some trouble taking up programming again. :\ Hi all
This part is integral to my site and im panicking as i cant seem to find an answer...
When someone clicks a link on my page with the below code it only does it as services... how can i create a paypal link to charge as friends and family PLEASE PLEASE PLEASE HELP <form id="payid" name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="<?php echo $row1['EMAIL']; ?>"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="item_name" value="BALL"> <input type="hidden" name="amount" value="<?php echo preg_replace( '/[^0-9,"."]/', '', $row['PRICE'] ); ?>"> <!--<input type="hidden" name="return" value="http://www.theeasypc.co.uk/lottery/heandal.php">--> <input type="hidden" name="return" value="http://www.theeasypc.co.uk/lottery/heandal.php?success=1"> <input type="hidden" name="cancel_return" value="http://www.theeasypc.co.uk/lottery/heandal.php?error=1"> <!-- Where to send the PayPal IPN to. --> <input type="hidden" name="notify_url" value="http://www.theeasypc.co.uk/lottery/heandal.php" /> <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> I can see the its set to business in one flag but ive tried to change thie to f&f, personal, friends, family, nothing works also tried "_donations"
Here is the error code I am receiving;
Parse error: syntax error, unexpected $end (line 41)
The error message has consistently identified the statement in the else clause. Thanks for any help.
<?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Blah</title> <link rel="stylesheet" type="text/css" href="defaultcss.css" /> </head> <body> <div id ="wrapper"> <h2>Blah Forum Demo</h2> <p>Creating basic login functionality</p> <?php if (!isset($_SESSION['uid'])) { echo "<form action = 'login_parse.php' method ='post'> Username: <input type ='text' name='username' /> Password: <input type ='password' name='password' /> Submit: <input type ='submit' name='submit' value='Log In' /> "; } else { echo "<p>You are logged in as ".$_SESSION['username']." • <a href='logout_parse.php'>Logout</a>; } ?> </div> </body> </html> Hi Guys http://www.phpfreaks.com/forums/Smileys/nrg_alpha/cool.gif Cool I have social networking application. I am trying to query a database to get the ids of all the users friends. With the ids of all the users friends I am then trying to query a second database with the status feed that contains all users status data. I would like to echo the users friends status data only from the second database code is below hope you can help. Thank you. <?Php session_start(); ?> <?Php //connect. include("connect.php"); //Time ago coverting code. include_once("classes/develop_php_library.php"); // Include the class library $id=$_SESSION['id']; /*find-out users friends*/ $findperson=mysql_query("SELECT * FROM friends WHERE sessid='$id'"); $timeAgoObject = new convertToAgo; // Create an object for the time conversion functions $findfriend=mysql_num_rows($findperson); //Count if the person has any friends. If they have friends get the ids of all their friends if($findfriend>0) { while($rati=mysql_fetch_assoc($findperson)) { $fried=$rati['friendid']; //query the status table to give the users friends status. $mediafeeds=mysql_query("SELECT * FROM status WHERE userid='$fried' LIMIT 0,8"); $media_num=mysql_num_rows($mediafeeds); } //count to see if their any status updates from users friends. if($media_num>0) { //display all the users friends status data. $datamedia="<TABLE BORDER='0' CELLPADDING=8 bgcolor='#FFFFFF' align='center' width='350px' height='30px'>"; while($mini=mysql_fetch_assoc($mediafeeds)) { $user_id=$mini['userid']; $viewer_nme=$mini['username']; $viewer_picture=$mini['viewerpics']; $media_pic=$mini['contentpic']; $desc_ption=$mini['description']; $date_time=$mini['date']; $convertedTime = ($timeAgoObject -> convert_datetime($datetime)); // Convert Date Time $datetime = ($timeAgoObject -> makeAgo($convertedTime)); // Then convert to ago time .. //This is just a table with the data of all the users friends data. $datamedia.="<tr><td valign='top' cellpadding='5' width='10%' bgcolor='#FFFFFF' align='center' >$viewer_nme<br/><a href='friendsprofile.php?uid=$uidd&&viewer=$id'><img src='".$mediapic."' width='80' height='80' align=left></td> <td valign='top' align='left' cellpadding='5' width='60%' bgcolor='#D3D3D3' cellpadding='0'>$introduction<br/>$titlenamed$titled<br/>$descd$desc_ ption<br/><br/>$datetime</td></tr>"; } $datamedia.="</TABLE>"; echo $datamedia; } else { echo "<font color='#333333' size='2' face='sans-serif' align=left><div align='center'> Your friends have not current activities.</div></font>"; } } else { } I am trying to make a filter to show posts from mutual friends between you and the persons profile you're on, I have somewhat of an idea on how to write the mysql query (it needs to be just one query, not two(which would be the easy way of doing it)). the "friends" table has: "friend_1" and "friend_2" and the "posts" table: "to_id" and "from_id" The PHP variables would be: "$session" and "$id" id would be the users Id of the profile you're on. Thanks, any help would be appreciated. I'm working on a Social Network from scratch. I'm stuck on how to store friend relationships between users? On one topic here, I found an idea. Have a table with 3 columns; id,user_1,user_2 each relationship would have a new row in the database. Would this be the best way to do this? I can imagine the table would get quite big. If each user has 100 friends and there's 10000 users that's 1000000 rows. etc im creating a members website and i want to show how many people are logging, in my database i have a col named online every time somone logs in there online goes from 0 to 1 and when thay log out it goes back to 0. i need to know how to show the total people that have 1 in there online part of the data base iv tryed this code and its not working <?php $result = mysql_query("SELECT online FROM `members` WHERE online='1'"); $row = mysql_fetch_row($result); echo $row; ?> this works in the sql console in phpmyadmin |