开发者

Threaded Messaging System

开发者 https://www.devze.com 2023-04-04 11:42 出处:网络
Am building a threaded messaging system, i have the following tables conversations_inbox id R_id S_id message

Am building a threaded messaging system, i have the following tables

conversations_inbox
id
R_id
S_id
message
read
post_time
conv_id

conversation_outbox 
id
R_id
S_id
message
read
post_time
conv_id

conversation_meta
id
sender_id
reciever_id
datetime

The conversations_inbox and conversation_outbox have a foreign key conv_id which tracks a messaging thread between two users I hit a snag when i was working on the messaging inbox, am trying to group the messages in the inbox by the sender_id(S_id) instead 开发者_Go百科of show each new message a user receives as new row.So all the messages to user in the box is grouped under the user that sent it and the newest message from that user is displayed.

i have tried

function get_user_conversations($user_id) {
       //Load Models
       $this->load->model('conversation_model');
       //Load helper
       $this->load->helper('date');
       //database query
       $q = $this->db->select('R_id,message,post_time,read,conv_id')
                     ->from('conversations_inbox')
                     ->where('R_id',$user_id)
                     ->group_by('S_id')
                     ->order_by('post_time','desc')
                     ->get();
        $conversations = $q->result();
        return $conversations;
   }

But it only returns one row of data for each Sender id Please i'd really appreciate if someone could point me in the right direction


First I'll state that before now I've never heard of codeigniter...

I'm thinking its because you call ->order_by('post_time','desc') after group_by, try switching those two around, order them while they are not grouped is the thought...

Just found this forum with a similar problem

0

精彩评论

暂无评论...
验证码 换一张
取 消