I am creating a basic PM system for my website. I have just a basic table for a pm:
mysql>describe PM;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| PMID | mediumint(9) | NO | PRI | NULL | auto_increment |
| toID | mediumint(9) | NO | | | |
| fromID | mediumint(9) | NO | | | |
| to_name | varchar(100) | YES | | NULL | |
| from_name | varchar(100) | YES | | NULL | |
| about_itemID | mediumint(9) | YES | | NULL | |
| about_item | varchar(100) | YES | | NULL | |
| title | varchar(100) | NO | | | |
| body | text | NO | | | |
+--------------+--------------+------+-----+---------+----------------+
and this table:
mysql> describe User_has_PMs;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| PMID | mediumint(9) | NO | | | |
| isvisible | tinyint(4) | NO | | 1 | |
| userID | mediumint(9) | NO | | | |
| UHPID | mediumint(9) | NO | PRI | NULL | auto_increment |
+-----------+--------------+------+-----+---------+----------------+
The reason I have a User_has_PMs
table is because I want users to have the ability to remove PMs, but obviously since PMs will show up in more than one mailbox I can't let them just delete PMs, so I firgured I would have a table that stores which PMs are visible to a user and which aren't.
I was hoping I could make my life simple and use a CREATE TRIGGER to auto_fill this table when a user sends a PM. But I'm curious if this would work as this would be a back-to-back query on the same data, a write followed by a read and I'm afraid even if it lets me do this, that it might time out. I could do this with PHP, and I'm not opposed to that but I was hoping for something easy like a trigger.
What are your thoughts?