Jump to content

Creating Facebook style messages


zander1983

Recommended Posts

Hi

Im created a market place website, sort of like eBay. I want to allow the shop owners to be able to message the user who has purchased an item from them and vice-versa. I want it to be like Facebook where a user sends a message, and if they reply, it becomes a thread which they reply to. But if a user send a message thats not in reply to a thread, a new thread is formed

 

What I'm looking for is the correct model to use. I set up these 2 table:

 

Message table

 

MessageID -> primary key

FromID -> id of sender

ToID -> id of receiver

Message -> the text of the messsage

Date -> date message was sent

 

Thread table

 

ThreadID -> ID linking messages together that aer in the same thread

MessageID -> foreign key to Message table

 

I want to know, am I on the right track with this? Its loooking like I'll need to use a cursor to get back the Username of the FromID person and ToID person in the same row. i dont like cursors!

 

Any tips on what i should do or does anybosy have links to a site with a tutorial on building a system like this?

 

Thanks in advance

Link to comment
Share on other sites

You could add a `replyto` field in your first table, and get rid of the second table altogether.  Just include the `id` of the first message in the `replyto` field if it's a direct reply, otherwise have it set to 0.

 

When you select your messages from the database, do a double ORDER BY.. first on the field `replyto` and second on the field `date`.  Any rows with a `replyto` value of 0 will be standalone messages (or the first message of a thread), and all others will be replies.

 

Then if a user is viewing a message with `id` of 45, any messages with `replyto` of value 45 should be printed as well in a thread style.

Link to comment
Share on other sites

good idea, ill use a replyto field.

 

i presume i need to use a cursor to get a row with:

 

- the message

- the date

- username of sender

- username of receiver

 

i need this all in one row. Message table joined to Member table, which contains usernames. i alwys try to avoid cursors, so complex. but seems unavoidable here..

Link to comment
Share on other sites

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.