dougouqin0763 2011-10-09 20:33
浏览 81
已采纳

使用php codeigniter从mysql数据库显示数据时出错

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) {
            //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?

  • 写回答

1条回答 默认 最新

  • drnl10253 2011-10-09 20:42
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功