doulong4169 2016-11-22 15:34
浏览 23
已采纳

如何在codeigniter中的同一页面中获得多个查询结果

Hy, I am working in codeigniter and I need to get multiple results on the same page. How I can do it.

Look at my code of Model, Controller and view.

Model:

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();

     }

controller:

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

view:

<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>

I get data of a continent "asia" from my database and display in a table. similarly i have to get some other data on the same page. Help me out please

  • 写回答

2条回答 默认 最新

  • dou5454954610 2016-11-22 15:39
    关注
    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);
    }
    

    Add another table to your view and iterate over the europe data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行