I am trying to display data from a database table I am using codeigniter elementary thing, but I do not understand what the problem is
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: record
Filename: views/main.php
Line Number: 55
controller Main.php
public function index()
{
$data['records'] = $this->PhoneBook->get_records();
$this->load->view('main',$data);
}
model PhoneBook.php
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();
}
view main.php
<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>
Line Number: 55 is
<td class="active"><?= $record->name ?></td>
array $data
Array
(
[records] => Array
(
[0] => stdClass Object
(
[id] => 1
[name] => фффф
[discription] => ыыыы
[phone] => 8454
)
[1] => stdClass Object
(
[id] => 2
[name] => ппапрпр
[discription] => аааааааааааа
[phone] => 645645
)
)
)