2016-11-22 103 views
0

Hy,我在codeigniter工作,我需要在同一頁上獲得多個結果。我如何做到這一點。如何獲得多個查詢結果在codeigniter中的同一頁

看看我的模型,控制器和視圖的代碼。

型號:

function asia(){ 
    $this->db->distinct(); 
    $this->db->select(); 
    $this->db->from('travels_detail t'); 
    $this->db->join('all_destination a','t.destination = a.destination','inner'); 
    $this->db->where('region', 'asia'); 
    $this->db->group_by('t.destination'); 
    $query= $this->db->get(); 
    return $query->result_array(); 

    } 

控制器:

function asia(){ 
     $data['asia'] = $this->travel->asia(); 
     $this->load->view('testing', $data); 
     } 

觀點:

<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Document</title> 
</head> 

<body> 
    <table border="1"> 
    <tr> 
    <td> Departure </td> <td> Destination </td> 
    <td> Airline </td> <td> Fare </td> 
    <td> Type </td> <td> Via </td> 
    </tr> 
<?php foreach($asia as $row){ ?> 
<?php 
    echo '<tr> 
    <td> '.$row['departure'].' </td> 
    <td> '.$row['destination'].' </td> 
    <td> '.$row['airline'].' </td> 
    <td> '.$row['fare'].' </td> 
    <td> '.$row['type'].' </td> 
    <td> '.$row['via'].' </td> 
    </tr>'; 
} 
    ?> 
</table> 
</body> 
</html> 

我從我的數據庫,並顯示在一個表中的大陸 「亞洲」 的數據。同樣,我必須在同一頁面上獲得一些其他數據。幫助我請

回答

0
function asia() 
{ 
    $data = [ 
     'asia' => $this->travel->asia(), 
     // The fact that the controller method is named `asia`, 
     // does not restrict you to only call the asia() method 
     // on your model. Do whatever you want! 
     'europe' => $this->travel->europe() 
    ]; 

    $this->load->view('testing', $data); 
} 

將另一張表添加到您的視圖並遍歷歐洲數據。

+0

$asia,並鑑於我又foreach循環$europe方式???例如foreach($ europe as $ europe_row){} –

+0

是的,當然,爲什麼不呢? – sepehr

+0

以及我將如何在模型中返回多個result_array()? –

0

型號:

function region($value){ 

    $this->db->distinct(); 
    $this->db->select(); 
    $this->db->from('travels_detail t'); 
    $this->db->join('all_destination a','t.destination = a.destination','inner'); 
    $this->db->where('region', $value); 
    $this->db->group_by('t.destination'); 
    $query= $this->db->get(); 
    return $query->result_array(); 
} 

控制器:

​​

只需使用你已經使用鑑於

相關問題