czukoman20 Posted October 12, 2007 Share Posted October 12, 2007 Ok i was wondering something mysql_query("INSERT INTO userdata (Username, Username2) VALUES ('$user2', '$user1')"); I am inserting data using this code into my userdata table in mysql. and now i have just crossed a problem. The problem is that Value $user2 is going to be the same sometimes. When this code is initiated and there is information that is the same in the database.. it doesnt make a new area with the information. For example. The datatabe userdata looks like this.. Username, Username2 Bobby123 Bobbiesbuddy123 Then Bobby 123 wants another buddy i want to be able to add another column right under that Bobby123 Bobbiesbuddy123-2 But when any part is the same it doesnt submit. is there a way around this. or am i just doing this the wrong way? Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/ Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 It sounds like what you want is another table. How exactly do you want buddies to work? Are all buddies also users? Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368112 Share on other sites More sharing options...
czukoman20 Posted October 12, 2007 Author Share Posted October 12, 2007 Yea all the buddies are users as well. its a process they find another user, and then click add buddy. and the user is added on their buddy list. then going back to the buddy list it will look at all the information that is in my datatable. ok so username wants username2 as their buddy. they click add to buddy it then writes the data in the database that includes First guy. His buddy username username2 if username want username3 to be his buddy also. then it will write with both in the table username username2 username username3 then when they want to view all of their buddies. the php document searches through the userdata table. and finds all of His buddy information that is listed next to First guy. and it will display it. I just want to know if there is code that can make it write it like this in the database. or if i have to do this another way Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368128 Share on other sites More sharing options...
czukoman20 Posted October 12, 2007 Author Share Posted October 12, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368186 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 You want to add a Buddy table. It will look something like this. Buddy ---------------- ID UserID BuddyID 1 12 13 2 12 2 3 12 14 4 14 13 5 14 12 UserID points to the ID field in the User table, and BuddyID also points to the ID field in the User table. In the example I gave above it might be something like this User(12) requested User(13) as a buddy User(12) requested User(2) as a buddy User(12) requested User(14) as a buddy User(14) requested User(13) as a buddy User(14) confirmed User(12) as a buddy If that's your whole table, the only buddies in the database are users 12 and 14. You could simply have it that if someone requests a buddy, it's granted, so record 5 in the table is unnecessary and redundant, but that would probably be more complex. I suggest the previous method. Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368188 Share on other sites More sharing options...
czukoman20 Posted October 12, 2007 Author Share Posted October 12, 2007 ok so what would the coding be for the first part u mentioned. because that would still remain the same problem. .. it doesnt record the info if anything matches Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368201 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 What does your table structure look like? What does your code currently look like? Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368215 Share on other sites More sharing options...
czukoman20 Posted October 13, 2007 Author Share Posted October 13, 2007 mysql_query("INSERT INTO userdata (Username, Username2) VALUES ('$user2', '$user1')"); this is the code. for the .php file. i already have the variables for user2 and user1. my database currently is table= userdata Username varchar 40 Username2 varchar 40 Thats my current database for this. Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-368407 Share on other sites More sharing options...
MmmVomit Posted October 15, 2007 Share Posted October 15, 2007 Get rid of Username2 from the userdata table. Add a second table called Buddies. It should have the following columns. ID Autonumber UserID Integer BuddyID Integer Quote Link to comment https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/#findComment-369965 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.