douqi1625 2015-01-02 11:29
浏览 46

致命错误:调用非对象上的成员函数where()

i got this fatal error when i run this on browser please solve my problem...i don't get whats wrong with this code.........Fatal error: Call to a member function where() on a non-object

Fatal error: Call to a member function where() on a non-object

model

<?php

        class News extends CI_Model
        {
        function Users(){
        //call model constructor

        parent::Model();
        //load database
        $this->load->database();
        }

        public function get_all_news(){

        $this->db->get('news');
        if($query->num_rows()>0){
        //return result set as associate array

        return $query->result_array();


        }

        }
        public function getnews($field,$param){

        $this->db->where($field,$param);

        $query=$this->db->get('news');
        // return result set as accosiate array

        return $query->result_array();
        }

        public function getnumnews(){
        return $this->db->count_all('news');
        }

        }

        ?>

controller

<?php
    class News_data extends CI_Controller{

    public function Users(){

    // load controller parent

    parent::Controller();

    // load ‘Users’ model



    }

    public function index(){
    $this->load->model('News');
    $data['users']=$this->News->getnews('id <',5);

    $data['numusers']=$this->News->getnumnews();

    $data['title']='Displaying user data';
    $data['header']='User List';

    // load ‘Show_data’ view
    $data['title']='Display data';
    $this->load->view('Show_data',$data);

    }

    }
    ?>

view

</head>

<body>

<h1><?php echo $header;?></h1>

<ul>

<?php foreach($users as $user):?>

<li>

<p><?php echo $user['id'].' '.$user['title'].' '.$user['tetxt'];?></p>

</li>

<?php endforeach;?>

</ul>

<p><?php echo 'Total number of users :'.$numusers;?></p>

</body>

</html>

?>
  • 写回答

2条回答 默认 最新

  • donglu7816 2015-01-02 11:32
    关注

    You may not initialising the db object $this->db here $this->db->where($field,$param); OR your $this->db is null.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法