PHP - Help Showing Friends Added
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 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. 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, 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 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 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. :\ 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 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. 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 am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here. Thank you for any assistance I may get!! - Amy - Code: [Select] <body><font color="006600"> <div style="background-color:#f9f9dd;"> <fieldset> <h1>Asset Entry Results</h1> <?php // create short variable names $tag=$_POST['tag']; $serial=$_POST['serial']; $category=$_POST['category']; $status=$_POST['status']; $branch=$_POST['branch']; $comments=$_POST['comments']; if (!$tag || !$serial || !$category || !$status || !$branch) { echo "You have not entered all the required details.<br />" ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $tag = addslashes($tag); $serial = addslashes($serial); $category = addslashes($category); $status = addslashes($status); $branch = addslashes($branch); $comments = addslashes($comments); } //@ $db = new mysqli('localhost', 'id', 'pw', 'inventory'); $db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database"); $query = "insert into assets values ('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." asset inserted into Inventory."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> </fieldset> </div> </body> this is my first post so I hope someone can help find a solution to this problem. I created this website in wordpress www.porthopehealthcentre.com It displayed correct in firefox but not ie. There was an extra closing </div> tag in my header php. I deleted this and now it displays correct in ie but not firefox. Can I somehow link to two different header files one for ie and one for firefox? if so how do I do this? Or is there an easier solution to this. I would really appreciate someones help as this is the final thing that needs adjusting to finish the job. 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 Hi, Im building a management web application that can contain sensitive information for people, allow for cheques to be printed, amoung other things. Im wondering what are some extra security features that could be added as some users may not want to have the web application available outside their business. I would preffer doing this without having to run the server locatlly on thier machine. i was thinking something like only allowing certain ip address's to access the sites login. Anyone have any other/better ideas? For some reason this only allows one SQL to be added... // SQL Connection $username="monstert_admin"; $password="admin"; $database="monstert_admin"; $connection = mysql_connect("localhost", $username, $password) or die("Connection Failure to Database"); // Select Database mysql_select_db($database, $connection) or die ($database . "No Database" . $username); //Select everything from the the table $MyQuery = "SELECT * FROM photos"; $retrieve = mysql_query($MyQuery) or die(mysql_error()); if(mysql_num_rows($retrieve) != 0): $row = mysql_fetch_assoc($retrieve); else: echo ''; endif; if(isset($_POST['Submit']) && !$errors) { $url = $newname; include('img.php'); $image = new SimpleImage(); $image->load($url); $image->resize(500,315); $image->save($newname); mysql_query("INSERT INTO photos (url) VALUES ('$url')"); echo "File Uploaded Successfully as <i> "; echo $newname; echo "</i>"; } What would the issue be? I only have two columns - ID and url Thanks in advance! I have a membership site that a user creates a username and password at registration. The user logs in and all that works. The usersname is located in the database under users. Each page is protected and you must login to access it. Here is the code for that
checkLogin('2'); $getuser = getUserRecords($_SESSION['user_id']);If the user login is correct they have access to the page. This all works fine as I said. On this page is a form that gets filled out. All the data except the username is added to the database for the contents of this form. I need to have the username added to the database to track who the data belongs to. Here is the code I have for this, can some tell me where I messed up. The line under the the code <body> pulls the username and the echo command prints the username on the page. I repeated this code under the if ($_SERVER['REQUEST_METHOD'] == "POST") code and it also prints the username. <?php // this is processed when the form is submitted // back on to this page (POST METHOD) if ($_SERVER['REQUEST_METHOD'] == "POST") { $usernow = $getuser[0]['username']; $userid = $usernow; echo "$userid"; # escape data and set variables $userid = addslashes($_POST["userid"]); $date = addslashes($_POST["date"]); $temperature = addslashes($_POST["temperature"]); $ph = addslashes($_POST["ph"]); $ammonia = addslashes($_POST["ammonia"]); $nitrite = addslashes($_POST["nitrite"]); $nitrate = addslashes($_POST["nitrate"]); $phosphate = addslashes($_POST["phosphate"]); $gh = addslashes($_POST["gh"]); $kh = addslashes($_POST["kh"]); $iron = addslashes($_POST["iron"]); $potassium = addslashes($_POST["potassium"]); $notes = addslashes($_POST["notes"]); // # setup SQL statement $sql = " INSERT INTO water_parameters "; $sql .= " (id, userid, date, temperature, ph, ammonia, nitrite, nitrate, phosphate, gh, kh, iron, potassium, notes) VALUES "; $sql .= " ('', '$userid', '$date', '$temperature', '$ph', '$ammonia', '$nitrite', '$nitrate', '$phosphate', '$gh', '$kh', '$iron', '$potassium', '$notes') "; // #execute SQL statement $result = mysql_query($sql); // # check for error if (mysql_error()) { print "Database ERROR: " . mysql_error(); } print "<h3><font color=red>New Water Parameters Were Added</font></h3>"; } ?> I have a form that has this: Code: [Select] <input type="text" name="notes_date" size="10" value="<?php echo date("m/d/Y");?>" /> I enter into the database after processing the variable like this: Code: [Select] $notes_date=date ("Y-m-d H:i:s", strtotime($_POST['notes_date'])); However, it gets stored at 2012-03-15 00:00:00 How do I fix this so that the current time gets stored instead of 00:00:00? I hope that subject made sense! I have a page where I want to generate page-specific keywords automatically. Actually I have some general keywords stored in a text file and then I add the page-specific ones after those. The problem is, however, solely caused by the keywords I pull from my text file. A "1" is added to my list of keywords. Consider a news page like so: news.php // ... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="<?php require('php/generateKeywordList.php'); ?>" /> </head> // ... And then generateKeywordList.php // I have omitted the part with the page-specific keywords, because it is not what causes the problem (commented it all out) set_include_path('/mypath/'); $str = require_once('includes/websiteKeywords.txt'); echo $str; // For some reason, the number 1 is added at the end of this string websiteKeywords.txt (it doesn't matter what I put in there) Code: [Select] these, are, my, keywords, for, my, website In my meta tag, the above would be displayed as: Code: [Select] these, are, my, keywords, for, my, website1 I then tried to make a simple php page like this $keywords = require('includes/websiteKeywords.txt'); echo $keywords; ... and it worked. At the moment I have absolutely no idea where the number 1 comes from. So, basically if I include the keywords directly from the text file into my meta tag, it displays fine. If I make a simple php page where I echo out the keywords from the text file, it displays fine. But if I include my php script, which echos the keywords, into my meta tag, the number 1 is added at the end of the string. Am I completely missing something here or is this extremely strange? Thanks for any help! |