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

  • Home
  • SEARCH
  • 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 8322777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:29:52+00:00 2026-06-08T23:29:52+00:00

I am trying to implement a messaging system for the application I am currently

  • 0

I am trying to implement a messaging system for the application I am currently working at. The messages are stored in a table:

CREATE TABLE `message` (
  `MessageID` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `Thread` BIGINT(20) NOT NULL,
  `From` BIGINT(20) NOT NULL,
  `To` BIGINT(20) NOT NULL,
  `DateTime` DATETIME NOT NULL DEFAULT '2012-01-01 00:00:00',
  `Content` TEXT NOT NULL,
  PRIMARY KEY (`MessageID`),
  CONSTRAINT `FK_messageTo` FOREIGN KEY (`To`) REFERENCES `team` (`TeamID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_messageFrom` FOREIGN KEY (`From`) REFERENCES `team` (`TeamID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_thread` FOREIGN KEY (`Thread`) REFERENCES `thread` (`ThreadID`) ON DELETE CASCADE ON UPDATE CASCADE
);

Thread is another table that stores conversation threads, basically pairs of users.

When a user views a conversation they’ve had with somone, they should only be displayed the most recent, say, 10 messages. More messages are displayed on demand (click of a button, whatever). I am unsure what the most efficient way of pooling the database is in this case.

  • Taking out the whole thread each time and cutting it down obviously defeats the point.

  • Have a query along the lines of:

    SELECT *
      FROM message
     WHERE (to = {party1} AND `from` = {party2})
        OR (to = {party2} AND `from` = {party1})
     ORDER BY messageID DESC
     LIMIT {start}, {length}
    

where expressions like {name} are variables. I am unsure how LIMIT works here and if will be faster than my first method.

  • A third option would be to add another field (index) that is incremented within the thread (as the primary key in the message table is incremented whenever a new message is added anywhere in the system).
  • 1 1 Answer
  • 0 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-06-08T23:29:53+00:00Added an answer on June 8, 2026 at 11:29 pm

    Here one suggestion that comes to my mind after seeing your requirement is:
    Lets say if you have to display 10 conversations at a time and if user wants to see more he will be provided a button to see next 10 conversations.

    So what you can do is,first select the first 10 conversations and store the last conversations id number in some variable in the front end application.

    SELECT *
      FROM message
     WHERE (to = {party1} AND from = {party2})
        OR (to = {party2} AND from = {party1})
       AND messageid BETWEEN 1 AND 10
     ORDER BY messageID 
    

    When user clicks on a button to see next 10 conversations,then again send a query to sql engine with rang lastid+10. That is:

    SELECT *
      FROM message
     WHERE (to = {party1} AND from = {party2})
        OR (to = {party2} AND from = {party1})
       AND messageid BETWEEN 11 AND 20
     ORDER BY messageID 
    

    Also make sure you have proper indexes on the tables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a simple messaging system in CakePHP 1.3. What I need
I´m trying to implement session context data for a queued messaging system. The session
I am trying to implement new helpers for Google Cloud to Messaging . The
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
Trying to implement a rating system of users and postings. What is the best
Background: I'm trying to implement a messenging system in my app, and I'm writing
I'm trying to implement a simple tagging system (messing around in php)... I use
I'm trying to implement peer-to-peer messaging and file sharing utility within LAN, So does
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
I'm trying to implement EventArgs to pass a list of parameters to my messaging

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.