Hi. Im new to codeigniter, so im not sure if its something wrong with the codeigniter or my php. what im trying to do is if the records from a database table is empty echo a message. The message which ,"No records exist!", does display but then underneath is is a php error message box:
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
list.php
<body>
<ol>
<?php
foreach ($result as $record): ?>
<li>
Name : <?php echo $record->user; ?><br>
Email : <?php echo $record->email; ?><br>
Date / Time : <?php echo $record->postdate." / ".$record->posttime; ?><br>
Comment : <?php echo nl2br($record->comment); ?><br>
Action : <a href="<?php echo base_url('myguestbook/edit/'); echo $record->id; ?>">Edit</a>
/ <a href="<?php echo base_url('myguestbook/remove/'); echo $record->id; ?>">Delete</a>
<hr>
</li>
<?php endforeach; ?>
</ol>
<div align="center">
[ <a href="<?php echo base_url('myguestbook/create/'); ?>">Add</a> ]
</div>
</body>
model
function read($where, $length, $start) {
$this->db->limit($length, $start);
$query = $this->db->get_where('myguestbook', $where);
if ($query->num_rows() > 0) {
return $query->result();
}
else{
echo "No records exist!";
}
}
controller
public function view() {
$data['result'] = $this->myguestbook_model->read(null, null, null);
$data['title'] = 'List of All Comments';
$this->load->view('list', $data);
}