Jump to content

Storing Multiple Message in Database


upp

Recommended Posts

I need some advice, I'm not sure if this is the right section to post this or not but I'll give it a try. I am creating a website for a small group of people to be able to message back and forth. I ran into a problem when doing the whole reply to a message option. I dont want to have each individual message as a new entry in my database, and then look for each message in that conversation when loading the conversation, I thought about inserting something like +=+=+=+=+=+= in between messages in the conversation so that when i pull up that conversation i could just separate the messages into an array by looking for that +=+=+=+=+=+= in the string of text and separating all the messages out. I want to know if anyone knows a better way of doing this or if this is a good way to go. thanks for any suggestions.

Link to comment
https://forums.phpfreaks.com/topic/219806-storing-multiple-message-in-database/
Share on other sites

I have to agree with Pikachu on this, keep each msg seperate, add a replythread to field  and a loop which gets the the previous messages.
Pretty simple
pseudo code.

$replythread=$msg['replythread)

while(!empty($msg['replythread'])

{

    $next_msg=get_msg($replythread);

    if(!empty($next_msg))

    {

      $msg['body'].="+++++\n".$next_msg['body'];

      $replythread=$next_msg['replythread'];

  } else

      $replythread=0;

}

[/code]

 

another option is to store all the ids into replythread (as a string)

About the only bad thing of this method is that the field should be large enough to hold a very long list of ids.

 

pseudo code.

[/code]

$replythread=explode(',',$msg['replythread'])

foreach($replythread as $thread)

{

    $next_msg=get_msg($thread);

    $msg['body'].="+++++\n".$next_msg['body'];

    $replythread=$next_msg['replythread'];

}

[/code]

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.