Jump to content

[SOLVED] Ok im stumped!!, any idea's this is a tought one!


Recommended Posts

Hiya,

 

Basically i am making a social engine and i am very stumped!, I need to know how i would make it so that i can let my user's have friends!, Do i make a row in the database in there $username section called friends and everyone they add it will add there username ?, Or is there any other idea's ?,

 

Im stuck!,

 

Many Thanks

 

James.

No, you create a new table in the database, that you can call friends, which is indexed on their user ID, and where you add a new record for each friend, identified by their user ID in a second column

 

Ok thats confused me lol!,

 

Can someone explain like im a 2 year old please lol!,

 

Php & Mysql arent really my thing lol ?,

 

James.

Friends

 

ID_1  |  ID_2

1          2

1          3

 

 

This shows ID 1 is friends with ID 2 & 3.

 

Ooooooooh!, I see, Do you rekon you could post a SQL dump of somthing like this for me please :) ?, I dont know how to index mysql lol! ?,

 

James.

Can someone explain like im a 2 year old please lol!,

You already have a table called "users" (or similar) that has a record for each user looking something like:

USER_ID    USER_NAME
1          Mark Baker
2          Angelina Jolie
3          Jessica Alba
4          Charlize Theron
5          Thandie Newton

You create a new table called "friends"

Data would look like:

USER_ID    FRIEND_ID
2          1
3          1
4          1
1          5
5          1

Which says that users 2 (Angelina Jolie),3 (Jessica Alba), 4 (Charlize Theron) and 5 (Thandie Newton) are all friends with user 1 (Mark Baker); and that user 1 (Mark Baker) is friends with user 5 (Thandie Newton).

Really not sure how to make it easier, it's just a table with 2 INT fields.

 

Friends

 

ID_1   |  ID_2

1           2

1           3

 

 

This shows ID 1 is friends with ID 2 & 3.

 

Ooooooooh!, I see, Do you rekon you could post a SQL dump of somthing like this for me please :) ?, I dont know how to index mysql lol! ?,

 

James.

Really not sure how to make it easier, it's just a table with 2 INT fields.

 

Friends

 

ID_1  |  ID_2

1          2

1          3

 

 

This shows ID 1 is friends with ID 2 & 3.

 

Ooooooooh!, I see, Do you rekon you could post a SQL dump of somthing like this for me please :) ?, I dont know how to index mysql lol! ?,

 

James.

 

Hiya,

 

Well i understand what you mean i just cant get my head around how to do this :S,

 

would someone make me a SQL dump and i will modify it to my tables ect please :),

 

And would the PHP side of using this be hard ?,

 

James.

Really not sure how to make it easier, it's just a table with 2 INT fields.

 

Friends

 

ID_1  |  ID_2

1          2

1          3

 

 

This shows ID 1 is friends with ID 2 & 3.

 

Ooooooooh!, I see, Do you rekon you could post a SQL dump of somthing like this for me please :) ?, I dont know how to index mysql lol! ?,

 

James.

 

Hiya,

 

Well i understand what you mean i just cant get my head around how to do this :S,

 

would someone make me a SQL dump and i will modify it to my tables ect please :),

 

And would the PHP side of using this be hard ?,

 

James.

 

 

Anyone :) ?

 

 

James.

Can someone explain like im a 2 year old please lol!,

You already have a table called "users" (or similar) that has a record for each user looking something like:

USER_ID    USER_NAME
1          Mark Baker
2          Angelina Jolie
3          Jessica Alba
4          Charlize Theron
5          Thandie Newton

You create a new table called "friends"

Data would look like:

USER_ID    FRIEND_ID
2          1
3          1
4          1
1          5
5          1

Which says that users 2 (Angelina Jolie),3 (Jessica Alba), 4 (Charlize Theron) and 5 (Thandie Newton) are all friends with user 1 (Mark Baker); and that user 1 (Mark Baker) is friends with user 5 (Thandie Newton).

 

 

Ok, And was it INT tables i need ?

 

James.

 

Use the same type as you did with the other table - USER_ID. You most likely used INT.

Yes, it's int (integer). Numbers are always one of the integer types.

 

You won't find anyone here (or at least not many) who will write your code for you. We are here to help people having troubles with code, not to write code for people.

 

Keep trying though!

Yes, it's int (integer). Numbers are always one of the integer types.

 

You won't find anyone here (or at least not many) who will write your code for you. We are here to help people having troubles with code, not to write code for people.

 

Keep trying though!

 

 

Hiya,

 

No im not asking for people to do it for me!, I simply asked for idea's!, And guy's do i make a table with 2 fields ? both int ?

 

James.

make a table with 2 fields ? both int ?

 

Yes you do thats what both these guys have been telling you

Friends

ID_1  |  ID_2

1          2

1          3

 

 

This shows ID 1 is friends with ID 2 & 3.

 

 

::tbl_friends::

-id

-user_id

-friend_id

 

this is pretty simple.

make a table with 2 fields ? both int ?

 

Yes you do thats what both these guys have been telling you

Friends

ID_1  |  ID_2

1          2

1          3

 

 

This shows ID 1 is friends with ID 2 & 3.

 

 

::tbl_friends::

-id

-user_id

-friend_id

 

this is pretty simple.

 

 

Hiya again people,

 

I dont know if this is against the rule's so someone please let me know if it is, But iv have done the reaserch and i have made the SQL and the PHP, Just wondering if anyone could help me get it working because it dont seem to be at the moment :S,

 

Here's the Friend Request script:

<?
session_start(); 

require "../db/db.php"; 
require "../db/config.php"; 
require "../db/util.php";

isloggedin();
accessneeded("C");

if ($_SESSION[$username]){ //gets username
$username = htmlspecialchars($_GET[$username]); //friend
$by = $logged[$username]; //you
$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
}
} else {
echo ( "You need to be logged in" ); //not logged in
}
?>

 

Here's the New Friend script:

<?
session_start(); 

require "../db/db.php"; 
require "../db/config.php"; 
require "../db/util.php";

isloggedin();
accessneeded("C");

switch ($_GET[friends]) { //allows multiple pages
default:
$get = mysql_query( "SELECT * FROM `friend_requests` WHERE `username` = '$_SESSION[username]' "); //gets requests
while ($reqs = mysql_fetch_array($get))
{

echo ( "Friend Requests
$reqs[by] wants to be friends with you.
<a href='newfriends.php?friends=accept&user=$reqs[by]'>Accept</a><br/>
<a href='newfriends.php?friends=delete&user=$reqs[by]'>Delete</a>" ); //displays requests and shows accept delete links
}
break;

case 'accept': //accept page
if ($_GET[username]) { //get username

$add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[username]' , '$_SESSION[username]') "); // add to your friends list
$delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by` = '$_GET[username]' "); // deletes friend request
echo ( "$_GET[username] has been added as a friend and the request has been deleted" ); // echos the completion
}
break; //ends accept page

case 'delete': // delete page
if ($_GET[username]) { //gets username
$delete = mysql_query( "DELETE FROM `friend_requests` WHERE `by` = '$_GET[username]' "); // deletes friend request
echo ( "$_GET[username]'s request has been deleted" ); // echos completion
}
break; //ends delete page
} // ends switch

?>

 

Here's the SQL dump:

-- phpMyAdmin SQL Dump
-- version 2.11.9.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 24, 2009 at 02:36 AM
-- Server version: 5.0.67
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `share`
--

-- --------------------------------------------------------

--
-- Table structure for table `friends`
--

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 '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `friends`
--


-- --------------------------------------------------------

--
-- Table structure for table `friend_requests`
--

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

--
-- Dumping data for table `friend_requests`
--

 

Thanks.

 

James.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.