Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 863135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:15:39+00:00 2026-05-15T09:15:39+00:00

i have a system there user(sender) can write a note to friends(receivers), number of

  • 0

i have a system there user(sender) can write a note to friends(receivers), number of receivers>=0. Text of the message is saved in DB and visible to sender and all receivers then they login to system. Sender can add more receivers at any time. More over any of receivers can edit the message and even remove it from DB. For this system i created 3 tables, shortly:

users(userID, username, password)
messages(messageID, text)
list(id, senderID, receiverID, messageID)

in table “list” each row corresponds to pair sender-receiver, like

sender_x_ID — receiver_1_ID — message_1_ID
sender_x_ID — receiver_2_ID — message_1_ID
sender_x_ID — receiver_3_ID — message_1_ID

Now the problem is:
1. if user deletes the message from table “messages” how to automatically delete all rows from table “list” which correspond to deleted message. Do i have to include some foreign keys?

More important:
2. if sender has let say 3 receivers for his message1 (username1, username2 and username3) and at certain moment decides to add username4 and username5 and at the same time exclude username1 from the list of receivers. PHP code will get the new list of receivers (username2, username3, username4, username5) That means insert to table “list”

sender_x_ID — receiver_4_ID — message_1_ID
sender_x_ID — receiver_5_ID — message_1_ID

and also delete from table “list” the row corresponding to user1 (which is not in the list or receivers any more)

sender_x_ID — receiver_1_ID — message_1_ID

which sql query to send from PHP to make it in an easy and intelligent way? Please help! Examples of sql queries would be perfect!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:15:40+00:00Added an answer on May 15, 2026 at 9:15 am

    Your first problem is easy. You could do it by setting a foreign key on list. You’d set it up to CASCADE updates and deletes (so that DELETE FROM messages WHERE messageID = 5 would automatically delete all rows in list where messageID = 5 as well. You’d need to use InnoDB as the storage engine for this to work…

    For the second problem, that’s easy as well. Just insert the new rows in one query:

    INSERT INTO list (senderID, receiverID, messageID)
    VALUES (sender_x_id, receiver_4_id, message_1_id),
           (sender_x_id, receiver_5_id, message_1_id);
    

    And then remove the others in another:

    DELETE FROM list
    WHERE receiverID = receiver_1_id
      AND messageID = message_1_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any methods/systems that you have in place to incentivize your development team
Hi I'm using ms2005 for a simple calendaring system. We have three 'legacy' tables:
I have a system that combines the best and worst of Java and PHP.
I have a system in place which applies calculations to a set of numbers
I have a system where I query a REST / Atom server for documents.
I have a system that uses a meta refresh to a logout page, which
We have a system where customers, mainly European enter texts (in UTF-8) that has
I have a system which sits on a web server and generates files on
I have two system calls GetSystemTime() and GetThreadTimes() that I need to calculate the
I have a system in which different server processes are handling requests passed as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.