jamesxg1 Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/ Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Create a friends table and link the two IDs. Not too "tought". Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744492 Share on other sites More sharing options...
Mark Baker Posted January 23, 2009 Share Posted January 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744493 Share on other sites More sharing options...
jamesxg1 Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744496 Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Friends ID_1 | ID_2 1 2 1 3 This shows ID 1 is friends with ID 2 & 3. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744499 Share on other sites More sharing options...
justinh Posted January 23, 2009 Share Posted January 23, 2009 It's called Database Normalization. say you have 2 tables: ::tbl_user:: -user_id -user_name ::tbl_friends:: -id -user_id -friend_id this is pretty simple. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744505 Share on other sites More sharing options...
jamesxg1 Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744510 Share on other sites More sharing options...
Mark Baker Posted January 23, 2009 Share Posted January 23, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744512 Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744515 Share on other sites More sharing options...
jamesxg1 Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744521 Share on other sites More sharing options...
jamesxg1 Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744527 Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Google "create table mysql". Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744529 Share on other sites More sharing options...
jamesxg1 Posted January 23, 2009 Author Share Posted January 23, 2009 Google "create table mysql". Ok, And was it INT tables i need ? James. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744533 Share on other sites More sharing options...
Philip Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744549 Share on other sites More sharing options...
haku Posted January 23, 2009 Share Posted January 23, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744574 Share on other sites More sharing options...
jamesxg1 Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744802 Share on other sites More sharing options...
RichardRotterdam Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744805 Share on other sites More sharing options...
jamesxg1 Posted January 24, 2009 Author Share Posted January 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142136-solved-ok-im-stumped-any-ideas-this-is-a-tought-one/#findComment-744939 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.