Welcome Guest [Log In] [Register]
Add Reply
Friend_System updated
Topic Started: Jun 3 2009, 06:25 PM (236 Views)
hansmaulwurf

hi,

i tried the friend_system from admin but i wasn't satisfied with that. so i nearly wrote my own one.
the problem was, that you had to request a friendship from both sides. now it proofs if the friendship is already in the table.

i used only one table. for the activation i included the field aktiv. by a request it gets an 0 when the other user accepted the request in gets an 1.

check this out:

SQL
Code:
 

CREATE TABLE IF NOT EXISTS `friends` (
`id` int(10) NOT NULL auto_increment,
`friendname` varchar(225) NOT NULL default '',
`username` varchar(225) NOT NULL default '',
`aktiv` int(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;


newfriends.php
Code:
 

<?
echo "<br>Freundschaftseinladungen<br><br>";

/* Requested Username error checking */
$req_user = trim($_GET['user']);

switch ($_GET[friends]) { //allows multiple pages
default:
$get = mysql_query( "SELECT * FROM friends WHERE username = '$session->username' AND aktiv = '0'"); //gets requests
while ($reqs = mysql_fetch_array($get))
{

echo ( "<br>Anfragen<br>
$reqs[friendname] möchte dein Freund werden.<br>
<a href='main.php?section=neuefreunde&friends=accept&user=$reqs[friendname]'>Annehmen</a><br/>
<a href='main.php?section=neuefreunde&friends=delete&user=$reqs[friendname]'>Ablehnen</a><br><br>" ); //displays requests and shows accept delete links
}
break;

case 'accept': //accept page
if ($session->logged_in) { //get username

$add = mysql_query( "UPDATE friends SET aktiv = 1 WHERE friendname = '$req_user' "); // add to your friends list
echo ( "$req_user ist jetzt dein Freund." ); // echos the completion
}
break; //ends accept page

case 'delete': // delete page
if ($req_user) { //gets username
$delete = mysql_query( "DELETE FROM friends WHERE friendname = '$req_user' AND username = '$session->username'"); // deletes friend request
echo ( "$req_user's Anfrage wurde abgelehnt" ); // echos completion
}
break; //ends delete page
} // ends switch

?>


friendrequest.php
Code:
 

<?

/* Requested Username error checking */
$req_user = trim($_GET['user']);

echo "<br>Freundesanfrage<br>";

if ($req_user){ //gets username
$username = htmlspecialchars($req_user); //friend
$by = $session->username; //you

$proof = mysql_query( "SELECT * FROM friends WHERE username = '$session->username' AND friendname = '$username' || friendname = '$session->username' AND username = '$username'" );
//if($proof)
//{
$num_rows = mysql_num_rows($proof);

if($num_rows)
{
$friends = mysql_fetch_array($proof);

if($friends[aktiv] == '0')
{
echo "Du hast bereits eine Einladung an $username verschickt!";
}

else
{
echo "$req_user ist bereits dein Freund!";
}
}

else
{
$query = mysql_query("INSERT INTO friends ( username , friendname ) VALUES ( '$username' , '$by' )"); //inserts the request
echo ( "$username hat die Anfrage erhalten." ); //echos completion
}

}
?>


friendlist.php
Code:
 

<?
echo "<br>Meine Freunde<br>";

$getfriends = mysql_query( "SELECT * FROM friends WHERE username = '$session->username' AND aktiv = 1 || friendname = '$session->username' AND aktiv = 1" );
while ($friends = mysql_fetch_array($getfriends))
{
if($friends[friendname] != $session->username)
echo "<a href='main.php?section=profil&user=$friends[friendname]'>$friends[friendname]</a> <br>";

else
echo "<a href='main.php?section=profil&user=$friends[username]'>$friends[username]</a> <br>";

}

?>


i tried it out and i found no problems.

greetings
hans
Offline Profile Quote Post Goto Top
 
laurens

let me guess.. you're from germany XD
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

haha :P
Offline Profile Quote Post Goto Top
 
Admin
Administrator
nj havent looked through it but mine was buggy
Offline Profile Quote Post Goto Top
 
hansmaulwurf

ich bin ein berliner...
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

what language is tht?
Offline Profile Quote Post Goto Top
 
hansmaulwurf

its a quote from kennedy! he said this in good old germany...
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

ooohhhhh no wonder i got confuzzled :P

i google translated it from german but it came up the same and i was like :S
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Friends System · Next Topic »
Add Reply