dipti
dipti

Reputation: 71

Display two different array return value in single table in codeigniter

I want to show return two array value in a single table in view,i already run first array value in table.

controller

public function communication(){
     $session_data = $this->session->userdata('admin_logged_in');
    $id = $session_data['id'];     
    if ($this->session->userdata('admin_logged_in')) {
        $data['get_all_mail'] = $this->admin_model->get_all_mails($id);
        $data['get_out_mail'] = $this->admin_model->get_out_mails($id);           
        $this->load->view('communication',$data);
    }
}

model

function get_all_mails($id){
    $query = $this->db->query("SELECT * FROM t_communication_posting WHERE FIND_IN_SET($id, REPLACE(`to`, ', ', ',')) OR FIND_IN_SET($id, REPLACE(`cc`, ', ', ',')) OR FIND_IN_SET($id, REPLACE(`bcc`, ', ', ',')) <> 0");
    return $query->result_array();
}

view

                          <table id="myTable">
                            <tbody>
                                <?php foreach ($get_all_mail as 
                                  $get_all_mails) { ?>
                                    <tr onclick="return get_mail_content(<?
                    php echo $get_all_mails['m_id']; ?>)" id="target-list">                                     
                                        </td>                                                                     
                                <td class="email-title" >
                                    <?php echo $get_all_mails['from']; ?>
                                </td>
                                <td class="email-body" >
                                    <?php echo $get_all_mails['subject'] ?>
                                </td>                                                                       
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>

Here i want to run second array value ($data['get_out_mail']) in above table on view page,how i run two array value in single table.

Upvotes: 0

Views: 53

Answers (2)

Alex Mac
Alex Mac

Reputation: 2993

You can add another loop in your view file.

<?php foreach ($get_all_mail as $get_all_mails) {
    ?>
    <tr onclick="return get_mail_content(<?php echo $get_all_mails['m_id']; ?>)" id="target-list">                                     
        <td class="email-title" >
            <?php echo $get_all_mails['from']; ?>
        </td>
        <td class="email-body" >
            <?php echo $get_all_mails['subject'] ?>
        </td>                                                                       
    </tr>
<?php } ?>

<?php foreach ($get_out_mail as $get_out_mails) {
    ?>
    <tr onclick="return get_mail_content(<?php echo $get_out_mails['m_id']; ?>)" id="target-list">                                     
        <td class="email-title" >
            <?php echo $get_out_mails['from']; ?>
        </td>
        <td class="email-body" >
            <?php echo $get_out_mails['subject'] ?>
        </td>                                                                       
    </tr>
<?php } ?>

This will help you.

Upvotes: 0

JYoThI
JYoThI

Reputation: 12085

you can run the second foreach after completion of first foreach like below

<table id="myTable">
      <tbody>
           <?php foreach ($get_all_mail as $get_all_mails) { ?>

                    //...... tr here 

           <?php } ?>

          <?php foreach ($get_out_mail as $get_out_mails) { ?>

                 //...... tr here

          <?php } ?>

      </tbody>
</table>

Upvotes: 0

Related Questions