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.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么