一个函数codeigniter中的不同查询

时间:2017-06-02 04:14:52

标签: php sql codeigniter

我使用Codeigneter并且我创建了一个搜索功能,在我的函数中我想运行两个不同的查询,我想在不同的表中显示它们,我怎么能这样做Sorry I can't show the data

这是我的代码:

我的控制器

function showDetail(){
        // Retrieve the posted search term.
        $detailTiket = $this->input->get('ticket_id');
        // Use a model to retrieve the results.
        $data["result"]= $this->tracking_model->showDetail($detailTiket);
        $data1["result"]= $this->tracking_model->showDetail2($detailTiket);

        // Pass the results to the view.
        $this->load->view('tracking/tiket_detail',$data,$data1);
    }

我的模特

function showDetail($detailTiket)
    {   
        if($detailTiket==""){
            $detailTiket = "";
        }

        $showDetailTiket=$this->db->query("My Query1");

        return $detailTiketDown->result();
        }

function showDetail2($detailTiket)
    {   
        if($detailTiket==""){
            $detailTiket = "";
        }

        $detailTiketDown=$this->db->query("My query2");

        return $detailTiketDown->result();
        }

我的观点

<table Width='800'>  

        <?php
        foreach($data as $row){?>
<tbody>
    <tr>
        <td><?php echo $row->ticket_id; ?></td>
    </tr>

    <tr>
        <td><?php echo $row->created_time; ?></td>
    </tr>

    <tr>
            <td><?php echo $row->start_IT; ?></td>
    </tr>

<tr>
            <td><?php echo $row->estimasi_selesai; ?></td>
    </tr>

    <tr>
            <td><?php echo $row->name; ?></td>
    </tr>

    <tr>
            <td><?php echo $row->description; ?></td>
    </tr>

    <tr style="background-color: cyan">
            <td><b><?php echo $row->Status; ?></b></td>
    </tr>

    </tbody>
        <?php } ?>
                </table>
                </center>
                </div>



<div>
<table Width='1000'>
<?php foreach($data1 as $rows){ ?>  
<tbody>
        <tr>
            <td><?php echo $rows->Tgl_Waktu; ?></td>
            <td><?php echo $rows->PIC; ?></td>
            <td><?php echo $rows->Tracking_Ticket; ?></td>
            <td><?php echo $rows->Keterangan_Ticket; ?></td>
            <td><?php echo $rows->File_Pendukung; ?></td>
        </tr>
</tbody>
        <?php }?>
        </table>

1 个答案:

答案 0 :(得分:3)

您可以将关联数组等数据传递给视图

像这样改变你的控制器

<强>控制器

$data["result"]= $this->tracking_model->showDetail($detailTiket);
$data["result1"]= $this->tracking_model->showDetail2($detailTiket);

// Pass the results to the view.
$this->load->view('tracking/tiket_detail',$data);

查看:

表1:

 foreach($result as $row)
  {
     //for first result 
  }

<强>表2:

foreach($result1 as $row1)
  {
     //for second result 
  }