MAX POWER
MAX POWER

Reputation: 5458

User messaging system (PHP / MySQL)

I'm currently developing a user messaging system (similar to Facebook) for my existing site. I already have a users table and just need to integrate a messaging system now.

I started a thread on this yesterday (User messaging system) and made some progress but the structure has changed quite a bit so I'm starting a new question.

What I want to know is essentially what should the table structure look like? The requirements are as follows:

Here is what I have at the moment:

Table messages
==============
id
thread_id
from_user_id
subject
body
sent_date

Table message_threads
=====================
id
message_id
to_user_id
from_user_id
read_status

Something else to think about is when sending the same message to multiple recipients, should we store a seperate message for each recipient, or just one message?

Any guidance would be highly appreciated.

Upvotes: 2

Views: 4824

Answers (2)

Nick Soares
Nick Soares

Reputation: 3

$query = 'CREATE TABLE IF NOT EXISTS ' . $db->prefix . 'pm (
    `post_id` => $post->ID,
    `role_id` => $role_id,
    `sender` varchar(60) NOT NULL,
    `recipient` varchar(60) NOT NULL,
    `date` datetime NOT NULL,
    `read` tinyint(1) NOT NULL,
    `deleted` tinyint(1) NOT NULL,
    PRIMARY KEY (`id`)
) COLLATE utf8_general_ci;';

I believe having something structured in this nature would work.

Upvotes: 0

Phil
Phil

Reputation: 1110

I agree with @Eddsstudio: when the user sends a message put a copy of it in the "sent folder" and copies in the recipients inbox's. For any replies: create a new message in the primary senders inbox, not linked to the previous messages (i.e. no link to the message in the sent folder).

You can make the messages look more like a thread conversation in the way they're displayed on the screen to the user but a multiple message back-end will create far fewer headaches.

Upvotes: 2

Related Questions