Jump to content

Recommended Posts

I've got multiple tables I'm using for an internal messaging system that I'm creating.  I'm trying to keep the same message id ('messid') for messages regardless of what table they are saved in (inbox, saved, deleted...).  To do this, I've created a table named "allmessages" where every message sent is inserted and the 'messid' is generated using auto increment.  This allows me to keep all the information on all sent messages in one place rather than having to pull certain information from different tables.  From there, the message will keep the 'messid' when inserted into "allmessages".  Here's the problem I'm having: at the same time that I insert the information into the "allmessages" table, I need to insert some of the information into another table as well, including the 'messid' generated from the AI in "allmessages".  BUT as of now, I have no way to pull just that specific message because 'messid' is the only unique field that I have to use when querying the database.  Basically, if I use any other field (Like: "SELECT `messid`,`staffid`,`message`FROM `allmessages` WHERE `anything other than messid` = '$whatever'")  I would get multiple results because 'messid' is the only unique field AND it's part of the information I need to pull from the database.

 

I hope I'm making sense here... basically, I need to figure out a way to either use the 'messid' generated when inserted into "allmessages" and insert the same 'messid' into another table at the same time... OR use the 'staffid' field and pull all information from the last entry into "allmessages" and get the 'messid' to insert into a different table.

 

I would greatly appreciate any help.  I'm stumped on this one.

Link to comment
https://forums.phpfreaks.com/topic/212895-inserting-same-info-into-two-tables/
Share on other sites

without see your tables definition that could lead me to a different suggestion I will say... implement a database TRIGGER over the table "allmessages" ... it could take care of the insert in the other table automatically.

 

a quick google search should lead you to several examples regarding how to implement a Trigger over a table.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.