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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历