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
  • 2 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

Swing newbie question... I have a system where there is a large number of
I have a system where employees can upload files. There are three ways Upload
Once the system is shutdown there will be message in syslog file. I have
i have a note which can share it to evernote,i done it sucessfully.but there
We have a system built on seam/richfaces. There's this webpage where the tables are
Does Windows have the notion of system-wide shared memory segments and is there a
I currently have a Ruby on Rails system, and there are plans to port
Are there any standalone type conversion libraries? I have a data storage system that
I frequently work with the System.IO namespace. Is there a way to have that
We have an internal system where users can authenticate using Windows authentication but we

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.