PHP - More Efficient Way To Get Updates From Friends
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. 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) 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 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 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 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 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 have some code which i think is really inefficient especially as there will be more more conditions to be met. I was thinking about using s switch but don't know if this is possible or if it's best leaving as it is. Any ideas? if($parts[($i-1)]=="forum") { //do some code } else if($parts[($i-2)]=="forum") { //do code } else if (($parts[($i-1)]=="list-messages") && (isset($parts[($i+1)]))) { //do code } else { // do some code } this xml_parse_into_struct($iP=xml_parser_create(), curl_exec($ch), $bR, $bJ);xml_parser_free($iP); echo "::: ".strip_tags(str_replace("<br>","\n",$bR[$bJ['MESSAGE'][0]]['value']))."\n"; or... $xml = simplexml_load_string(curl_exec($ch)); foreach($xml->xml as $message){ echo strip_tags($message->message)."\n";} Just want to know which of these two would execute faster and if there was a better way that would be faster than both of these options? Thanks Code: [Select] <?php $IPaddress = $_SERVER['REMOTE_ADDR']; if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) { echo "<center><b><i>CWB permits you to views this page...</i></b></center></br>"; echo '<center><b><font size="5">'.$IPaddress.'</font></b></center>'; } else { echo "<center><b>CWB DOES NOT PERMIT YOU TO VIEW THIS PAGE</b></center>"; } exit; ?> how do I make it to where I dont have to keep adding on to Code: [Select] if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) i dont know why it doesnt update the db..someone help?? $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $strEditProfile = "UPDATE tblemployee SET EmployeeName='".$_POST["edit_thename"]."', Address1 = '".$_POST[edit_address1]."', Address2 = '".$_POST[edit_address2]."', DesignationID = '".$_POST[edit_des]."', Postcode = '".$_POST[edit_postcode]."', State = '".$_POST[edit_state]."', Country = '".$_POST[edit_country]."', Tel1 = '".$_POST[edit_contact]."' WHERE EEmail='".$_POST["edit_email"]."'"; $resEditProfile = mysql_query($strEditProfile); if($resEditProfile) echo "<img src=\"images/valid.jpg\" /> Profile updated!"; else echo "><img src=\"images/warning.jpg\">Error!"; I have a script that has a foreach loop. The script ususally runs for VERY VERY long time ( i have set_time_limit(0) Now what I need it to do is to echo some string at the end of each loop. However it doesn't. The script displays everything after its finished. That's not acceptable for me. I'm running xampp for windows. Hi, I am new to PHP and mySQL. I am working on a golf site where it will need to have the user update info through text boxes. There are two things: 1) It will need to keep an average of the last 6 rounds. The user will need to be able to input the current round score and have it bump the oldest score of the database. 2) Also, i have a database of players that will populate a <select>. Is there a way to have the user be able to add/delete player names from this database? My question is what functions are needed to get this done. And how does one go about implementing them. Thanks in advance! Taylor Hello, I'm new to PHP and I have come up with the following code for my navigation but I am sure there has to be an easier and more efficient way to do this. Someone please start me on the right path. Thanks Code: [Select] <?php //Get selected page/sub page if (isset($_GET['page'])) { $sel_page = $_GET['page']; $sel_sub_page = ''; } elseif (isset($_GET['sub_page'])) { $sel_page = ''; $sel_sub_page = $_GET['sub_page']; } else { $sel_page = ''; $sel_sub_page = ''; } ?> Code: [Select] <!--Begin Navigation--> <ul> <?php //run the loop to get the page titles $query = "SELECT * FROM pages ORDER BY position ASC"; $page_set = mysql_query($query); confirm_query($page_set); while($page = mysql_fetch_array($page_set)){ echo '<li><a href="content.php?page=' . urlencode($page['id']) . '">' . $page['page_name'] . '</a></li>'; //run sub page query to see if the ul tag is needed $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); $sub_page = mysql_fetch_array($sub_page_set); if ($sub_page !=''){ echo '<ul>'; } //run the sub page loop again to display the sub page title $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); while($sub_page = mysql_fetch_array($sub_page_set)) { echo '<li><a href="content.php?sub_page=' . urlencode($sub_page['id']) . '">' . $sub_page['page_name'] . '</a></li>'; } //run the sub page loop for the last time to see if the end ul tag is needed $query = "SELECT * FROM sub_pages WHERE page_id = {$page['id']} ORDER BY position ASC"; $sub_page_set = mysql_query($query); confirm_query($sub_page_set); $sub_page = mysql_fetch_array($sub_page_set); if ($sub_page !='') { echo '</ul>'; } } ?> </ul> <!--End Navigation--> |