Hi everyone!

Ok, let me quickly explain what I want to achieve. I have two tables.

The first table is Requests and it looks like this

+------------------------------+
|          Requests            |
+----+-------------+-----------+
| id |  user_from  |  user_to  |
+----+-------------+-----------+
|    |             |           |
|    |             |           |
|    |             |           |
|    |             |           |
+----+-------------+-----------+

When the request has been sent and the other user has accepted, they get MOVED from the requests table into the friends table, knowing that they now are indeed friends!

And here is my friends table:

+--------------------------------+
|            Friends             |
+----+-------------+-------------+
| id |   user_id   |  friend_id  |
+----+-------------+-------------+
|    |             |             |
|    |             |             |
|    |             |             |
|    |             |             |
+----+-------------+-------------+

Now my question to you is HOW DO I MOVE (once the request is accepted) THE DATA FROM THE REQUESTS TABLE TO THE FRIENDS TABLE???

And how will the query look if I want to perform this?

PLEASE help!!

Thanks a lot!

J

There is no MOVE in sql.

1. Select the request from the Requests table.
2. Insert a row in the Friends table with the new friend.
3. Insert another row with the keys reversed (friend_id is also a friend to user_id)
4. Delete the friend request entry in the Requests table.

That's it.

Ok cool... How will the SQL query look for that? :O

because I have a very good idea what I want to do but I just don't have a clue how to code this...

Referencing madCoder's query suggestions.

1. SELECT * FROM request_table WHERE request_id = 'request_id'
2. INSERT INTO friends SET friend = 'friend_name' WHERE user = 'person_adding_friend'
3. repeat step 2 with reversed vars
4. DELETE FROM requests WHERE request_id = 'request_id'

These are very basic queries, considering that you couldn't figure out the logic behind them, you may want to read about MySQL before attempting to do any actual database work. Things can get very messy....

Also, does the internet seriously need another social network? =). Hope this helps.

There is no MOVE in sql.

1. Select the request from the Requests table.
2. Insert a row in the Friends table with the new friend.
3. Insert another row with the keys reversed (friend_id is also a friend to user_id)
4. Delete the friend request entry in the Requests table.

That's it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.