2017-06-02 52 views
1

我用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> 
+0

可以能跑多發查詢並返回值作爲數組這樣返回的數組($ first_query_result,$ second_query_result); – JYoThI

+0

顯示您的相關代碼 – JYoThI

+0

@JYoThI,我已添加我的代碼。謝謝。 –

回答

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 
    } 
+0

謝謝,它爲我工作。 –

+0

很高興幫助你@RizkiPahlevi – JYoThI