用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1786|回复: 3
收起左侧

[HELP] 如何在视图中显示查询结果???

[复制链接]
发表于 2015-12-14 09:19:47 | 显示全部楼层 |阅读模式
数据库的表名:video_film

我在 model Test_m 中的代码:
        public function test_select()
        {
                $query = $this->db->get('video_film');
                return $query->result_array();
                //$this->load->view('test_v',$query);
        }


在 controller Test_c 中的代码

        public function index()
        {
                $this->load->model('test_m');
                $data = $this->test_m->test_select();
                $this->load->view('test_v',$data);
        }


在 view Test_v 中的代码:


<?php foreach ($video_film as $news_item): ?>
<?php echo $news_item['id']; ?>
<?php echo $news_item['name']; ?>
<?php endforeach; ?>


为什么总是提示:$video_film 未定义
???

正确的应该怎么写?

先谢谢了。
发表于 2015-12-14 10:33:08 | 显示全部楼层
在 controller Test_c 中的代码          public function index()         {                 $this->load->model('test_m');                 $data['video_film'] = $this->test_m->test_select();                 $this->load->view('test_v',$data);         }  这样就没问题了
发表于 2015-12-14 14:21:07 | 显示全部楼层
应使用$data['xyz']的格式
 楼主| 发表于 2015-12-17 09:34:29 | 显示全部楼层
多谢了,已经解决了。

本版积分规则