php - Codigniter linking queries. -


i sorry if n00b question cant seem head around problem.

i using mahana message library , trying create basic views , basic controller send message , retrieve messages. have sending message nailed (just about) , can view sent message on recipients profile.

this problem. want able show details of user sent message along side sent message on recipients view message page. these details stored in users table.

the question is, how run model query username, avatar location etc view_my_messages function in messages controller, based on result of get_all_threads($user_id) model in messaging model?

i have included code controller, view , model below.

controller:

function view_my_messages(){         $this->load->library('mahana_messaging');         $user_id = $this->session->userdata('id');          $data['message'] = $this->mahana_model->get_all_threads($user_id);          $this->load->view('messages/my_messages',$data);      } 

message model:

function get_all_threads($user_id, $full_thread = false, $order_by = 'asc')     {         $sql = 'select m.*, s.status, t.subject, '.user_table_username .         ' ' . $this->db->dbprefix . 'msg_participants p ' .         ' join ' . $this->db->dbprefix . 'msg_threads t on (t.id = p.thread_id) ' .         ' join ' . $this->db->dbprefix . 'msg_messages m on (m.thread_id = t.id) ' .         ' join ' . $this->db->dbprefix . user_table_tablename . ' on (' . user_table_tablename .'.'. user_table_id . ' = m.sender_id) '.         ' join ' . $this->db->dbprefix . 'msg_status s on (s.message_id = m.id , s.user_id = ? ) ' .         ' p.user_id = ? ' ;          if (!$full_thread)         {             $sql .= ' , m.cdate >= p.cdate';         }          $sql .= ' order t.id ' . $order_by. ', m.cdate '. $order_by;          $query = $this->db->query($sql, array($user_id, $user_id));          return $query->result_array();     } 

view:

<div class="row-fluid">      <div class="span12">         <div class="well">             <h3>view messages</h3>             <?php foreach($message $messagefield):?>              <h4><?php echo $messagefield['subject'];?></h4>              <?php endforeach; ?>         </div>     </div>  </div> 

thanks help!

@morph_bytesense - have 2 options:

1) msg_participants p table holds other people on thread (not sender), you can join users table once more & extend select stmt

2) ( not good, don't need extend library) in result, can foreach() loop , query on participants & query details

i recommend first option - i've never had ask before, might make enhancement


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -