开发者

Error in displaying data from mysql db using php codeigniter

I am trying to display data from db. It displays this error

  <p>Severity: Notice</p>
  <p>Message:  Trying to get property of non-object</p>
  <p>Filename: controllers/schedule.php</p>
  <p>Line Number: 57</p>

  <p>Severity: Notice</p>
  <p>Message:  Trying to get property of non-object</p>
  <p>Filename: controllers/schedule.php</p>
  <p>Line Number: 58</p>

here is my code in controller which, this code is related to this problem

$data['rows'] = $this->Model_scheduleSave->save_schedule($data);
$this->load->view('home_view',$data);

here is my view

if($rows) {
开发者_如何学C            //var_dump($rows);
            foreach(rows as $r) : 
                "<div>". $r->client_url ."</div>";
                "<div>". $r->admin_url ."</div>"; 
            endforeach;
        }

here is my model

public function save_schedule($data) {
    $query = "INSERT INTO schedule VALUES('',?,?,?,?,?,?,?)";
    $result = $this->db->query($query,$data);
    if($result) {
        $get_urls = "SELECT client_url,admin_url FROM schedule ORDER BY id DESC LIMIT 1";
        $results = $this->db->query($get_urls);
        if($results) {
            foreach($results->result() as $rows) {
                $data[] = $rows;
            }
        }
        return $data;
    } else {
        return false;
    }
}

Where am I making mistake?


In case your database query returns no result, the function will return the parameters passed to the function ($data). That might cause your error.

Another word of notice: Don't re-use variable names. You use $data to pass parameters to your function in the controller, and afterwards you assign the result to $data['rows']. You should use two variables, one for the view variables, and one for the function parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜