Jump to content

adding friends


runnerjp

Recommended Posts

ok ok lol

 

i want to do this,,,

 

sure you have all used myspace,facebook or some social network

 

well i want it so if you are a a friend of someone on a profile site... you can add them and they will be in your list of friends... this way they are the only 1ns allowed to see your profile and post on your comment box.

 

 

simplist :o.. i cant get my head round it... how do i get the other users id?? and once i have this how would i post them into db

 

my_id  |  friends_ids

  1              2,3

  2                2

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536953
Share on other sites

yes we all know what you're trying to do..... we're just wondering why someone with 1000 posts doesn't know this.....odd....

 

 

you would create a new row for each relantionship

 

id -- uid1 --- uid2

1      7          3

2      7          8

3      7          4

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536959
Share on other sites

Hey he might have 1,000 posts but that doesnt mean he knows everything about PHP.  Perhaps this is a new site that he's working on and is trying to do things he's never had any experience with. 

 

Now I myself have never done anything like this either though given time I don't think it would be too hard to figure out.  I'm sure one of you may have some real experience with it and can help get him on the right track instead of complaining that he doesnt know it because he has more posts than you.

 

Utlimately I would think that you'd have a few queries to handle this...  First one is to select uid from users where username = username, to get the user id of the user to be added.

 

Next one, insert it into say user_friends or something....  you'll be needing 2 id's for this..  the main id and the friends id... 

 

Then on the main page do a query from that as well -- you select all the information of the profile to get the uid of that member, and you have the viewers member id in a session (or if they are a guest it's not set)...    then you do something like..

 

select * from users_friends where uid = uid & fid = $_SESSION['uid'] limit 1;

 

then if its blank show an error saying they need to be friends of this person...  and if they are in there, it will show the page.

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536969
Share on other sites

No where he did he say 'make my site for me'...  He is only asking for help.  Sure he is asking for a lot of different things, but hey give him some basic answers like I did above, some ideas and help him get on the right track..  no need to make all the scripts for him, just give him a boost with some basic ideas...  that is being helpful, criticizing his PHP skills and his post count is not.

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536977
Share on other sites

Straight off of my site:

$query = "SELECT u.* FROM friends AS f INNER JOIN users AS u ON f.friend_id = u.user_id WHERE f.user_id = '{$_SESSION['user_id']}' AND f.accepted = 0";

 

 

 

Table named friends and table named users.  Users contains the user info.  Friends is setup like this:

user_id friend_id

4          5

4          6

5          9

 

 

Like that.

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536989
Share on other sites

hey..ok some harsh people on here... thaks radar and darkwater

 

ok i all i need to know is how would i go about getting the friends id... would it be from the url??

 

and also the best way to store it in the database

 

i never asked to write the code for me... just giving me the starting line so then i can put it the effort to finish

 

 

ok database looks good...thats what i was thinking.. didnt know if it would be too simple lol

 

how would i grab the friends username??

 

my current like is  website/memebers/username

 

 

like so

 

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

 

RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-536990
Share on other sites

humm ok so to get a users username...seems i use RewriteRule ^([^/.]+)/?$ members/index.php?page=profile&username=$1

 

i could get it byyyy

 

<a href='friendrequest.php?user=$username'>Add as Friend</a>

 

on the lines i think but its the $username im not so sure

 

then the firend request page would beeeeee

 

<?php
session_start(); //starts session
include "../settings.php"; //include config

{ 

if ($_GET[user]){ //gets username
$username = htmlspecialchars($_GET[user]); //friend
$by = $_session[username]; //the person
$query = mysql_query("INSERT INTO `friend_requests` ( `username` , `by` ) VALUES ( '$username' , '$by' )"); //inserts the request
echo ( "$username has been sent a request you must now wait for it to be accepted" ); //echos completion
} else {
echo ( "No request was made" ); // or no request sent
}
} 
?> 

 

this will work just grabbing the username of the friend

 

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537493
Share on other sites

ahh ok im getting Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/runningp/public_html/members/friendrequest.php on line 8

 

 

PHP

<?php
session_start(); //starts session
include "../settings.php"; //include config
{ 
if ($_GET['user']){ //gets username
$username = htmlspecialchars($_GET['user']); //friend
$by = $_session['username']; //the person
$query = mysql_query("INSERT INTO `friend_requests` ( `username` , `by` ) VALUES ( '$username' , '$by' )"); //inserts the request
echo ("$username has been sent a request you must now wait for it to be accepted"); //echos completion
} else {
echo ("No request was made"); // or no request sent
}
} 
?>

 

 

now i cant see any whitespace or t_encapsed can u :S

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537564
Share on other sites

ok lots of change... im now getting the error QUERY ERROR:

INSERT INTO friend_requests (username,by) VALUES ('emma','1')

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by) VALUES ('emma','1')' at line 1

 

<?php
session_start();

include "../settings.php";

if ( !empty($_GET['user']) ) {
  $username = htmlspecialchars($_GET['user']);

  $by = $_SESSION['user_id'];
  

  $query = "INSERT INTO friend_requests (username,by)
            VALUES ('$username','$by')";

  $result= mysql_query($query)
    or die("QUERY ERROR:<br />{$query}<br />" . mysql_error() );

  echo "$username has been sent a request you must now wait for it to be accepted";
  // useful in troubleshooting the SQL statement
  echo "<p>{$query}</p>";

} else {
  echo "No request was made";
} 
?> 

 

is this due to me using a id and a username

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537660
Share on other sites

ahhhh wait... by is allready used in sql...doh `by` will be the answer lol

 

 

while im here im working on the second part,, starting to get to grips with functions and was wondering

 

if i was to do this

 

$add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , 'function get_username') ");

 

how would i use the function proerly ??  new to this area

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537673
Share on other sites

Please stop using strings directly in your mysql query.  Set it to a variable then use it.  It makes your code MUCH neater.

 

$query = "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '" . get_username() . "')";

$add = mysql_query($query) OR die (mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537675
Share on other sites

ok i tried what you said and i got Warning: Missing argument 1 for get_username(), called in /home/runningp/public_html/members/friendrequest.php on line 13 and defined in /home/runningp/public_html/functions.php on line 309

 

function get_username ( $id )
{
	global $db;

	$query = "SELECT `Username` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id );

	if ( $db->RecordCount ( $query ) == 1 )
	{
		$row = $db->getRow ( $query );

		return $row->Username;
	}
	else {
		return FALSE;
	}
}

Link to comment
https://forums.phpfreaks.com/topic/104908-adding-friends/#findComment-537678
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.