2016-11-22 4 views
0

Hy、私は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_row 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(); 
} 

コントローラ:

​​

はちょうどあなたがビュー

関連する問題