sk811229 发表于 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 未定义
???

正确的应该怎么写?

先谢谢了。

Aloghli 发表于 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);         }这样就没问题了

page2page 发表于 2015-12-14 14:21:07

应使用$data['xyz']的格式

sk811229 发表于 2015-12-17 09:34:29

多谢了,已经解决了。
页: [1]
查看完整版本: 如何在视图中显示查询结果???