未定义的变量,不能显示数据库中的数据

时间:2016-10-04 08:35:06

标签: php codeigniter

我正在尝试显示数据库表中的数据 我正在使用codeigniter 基本的东西,但我不明白问题是什么

遇到PHP错误

严重性:注意

消息:未定义的变量:记录

文件名:views / main.php

行号:55

控制器Main.php

added on

模型PhoneBook.php

added at

查看main.php



public function index()
{
    $data['records'] = $this->PhoneBook->get_records();
    $this->load->view('main',$data);
}




行号:55是

public function get_records($conditions = null, $limit = null, $offset = 0, $order = null)
{
    if ($conditions != null) {
        $this->db->where($conditions);
    }
    if ($order != null) {
        $this->db->order_by($order);
    }
    $query = $this->db->get('phonebook', $limit, $offset);
    return $query->result();
}

数组$ data

<table class="table table-bordered">
  <tr>
    <td class="active">Name</td>
    <td class="active">Discription </td>
    <td class="active">Phone</td>
    <td class="active">Actions</td>
  </tr>

  <? foreach ($records as $record) {?>
  <tr>
    <td class="active"><?= $record->name ?></td>
    <td class="active"><?= $record->discription ?></td>
    <td class="active"><?= $record->phone ?></td>
    <td class="active">Actions</td>
  </tr>
  <? } ?>

</table>

0 个答案:

没有答案