Hello, I am trying to make a friends list for my website http://tackypenguin.com. I was thinking that I would insert a row into the database for each user. This row would have all of the person's friends listed in an array. The problem is, I don't know how I would delete a friend if someone wanted to delete it. Anyone have an idea? I have Googled, but I couldn't find anything about actually deleting part of the array.
I hope you are using usto-incrementing IDs for each new records added to the databaase. If you are, just run the following SQL: $sql="DELETE FROM table_name WHERE id='$id'"; PHP: where $id is the id of the record!
No. I was wondering if i could get, say user1, user2, user3, and user4, and insert them into one row that belongs to user 5. Have the all in one array, and explode them by "||" to get the friends listed.
hes not saying that he wants to delete them right now, he means when a user doesnt want someone on their friends list, that they can click delete and it deletes them from the array, i dont know how to do this, but i do get your question.
I understand the question, but your 'design' is wrong. You should have a row for each 'friend' of a user, so if user 2 is friends with 4, 7, 8 and 12, you would have four rows: Something like: RowID|UserID|FriendID 1|2|4 2|2|7 3|2|8 4|2|12 Then you just delete the row that contains the particular user ID and the particular friend ID.
But how many rows will you make in such way? Lets say you have 1000 users and each of them have 100 friends, just imagine how many rows would that take up. Also it will affect the speed of the application. Ryan's first approach about storing it using delimiters is more efficient than a new rows for every friend I feel.
Do you know how I would do it though. I had an idea, but how would I remove a friend if a user wanted to remove it?
Firstly, what's 100,000 rows? Nothing. If it's indexed correctly you won't have a problem and the size is negligible if you use sane fields. Secondly, and, as far as I'm concerned, more importantly: doing it with delimiters is wrong. Your row should contain a single 'fact'... all your asking for is more trouble in the long run. You know that at some point in the future the question will be asked "OK, so how many people have me as their friend?" You wanna do string searches, you go ahead.
But, I dont want to do that. Is there a way to delete from an array in a row in MySql? Thats my question.
$array = explode("|" $array); foreach ($array as $tmparray) { if ($tmparray != $arraytodelete) { $newarray .= $tmparray . "|"; } } $array = $newarray; deleted... [edit] Forgot to add the sql. $query = "UPDATE $UPDATE $tableName SET $columnName = $newValue WHERE $columnName = '$someValue'";
Hey I noticed on your web site also that you have it saying that your users need to register to your web site again. This is not the most professional approach to doing this, 1 easy way is to write a program to gather all users passwords and turn them into a hash if that is what you are trying to do. Just some advice because I have created a hole friends network before.
Bye the way. I just had to say, your friend has a pretty nice looking site. Just one thing cought my eye as ugly. You might wanna tell him to change the black lines to a light blue or even white. And also center the text between the lines.
Personally I think that there is many ways to make this look alot better then is does now. Some time and TLC really will need to be put into this site and I think it might have some potential.
Thanks from everyone. I had it to where it updated to md5 when the user logged in, but there was en error in it, and somehow it deleted all of my users. I have it green on the sidebar now, and when you login with your account, you can set a style, and it will be that style every time you login.