• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
foreach that has no value

#1
[eluser]Unknown[/eluser]
this has been my problem now because some of my data should be null
my problem is when I have null values i encounter this error

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/index.php

Line Number: 91


I wonder how to redirect this error to <?php echo No message found ?> or just blank without any error

my views
Code:
<?php foreach ($verses as $verseItem):?>
<?php echo form_open('church/verses'); ?>
&lt;?php echo $verseItem->title ?&gt;</th>
&lt;?php echo $verseItem->message ?&gt;
&lt;?php endforeach?&gt;
&lt;?php echo form_close();?&gt;

controller
Code:
function home() {
$this->load->model('m_verse');
$data['verses'] = $this->m_church->gethomeverse();
$this->load->view('index', $data);
}

model
Code:
public function gethomeverse () {
$query = $this->db->get('tb_verse');
if($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
}
Thanks in advance


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.