[eluser]Unknown[/eluser]
Hi,
I'm new to CI and a PHP beginner but would really like that code example to work in my project.
I'm trying to do a str_replace and the error is pointing to that command. I'm thinking that I would have to convert the object to an array first. Any help is appreciated.
Code:
Error Message: Undefined property: stdClass::$content
Controller:
Code:
function index()
{
$query = $this->db->query('SELECT bible_books.name, bible_verses.t, bible_verses.v FROM bible_books, bible_verses WHERE bible_books.id=bible_verses.b AND name="Matthew" LIMIT 0 , 20');
if ($query->num_rows() > 0) :
$result = $query->result();
foreach($result as $row) {
$row->content = str_replace('search','replace',$row->content);
$content[] = $row;
}
else :
$content = 'No records found';
endif;
$data['content'] = $content;
}
View:
Code:
<?php if (is_array($content)) : foreach ($content as $row) : ?>
<div class="item">
<span><?=$row->v?></span>
<span class="descr"><?=$row->t?></span>
</div>
<?php endforeach; else : ?>
<?=$content?>
<?php endif; ?>