I have a model that checks for entries en a database. Like this:
public function getByID($id)
{
if(false == is_numeric($id))
return false;
$images = array();
$query = $this->db->where("id_album", $id)->order_by("order", "ASC")->get("images");
foreach($query->result() as $row)
$images[] = $row;
return (object) $images;
}
In my view I want to know if I have a rows or not, to show the images or not. I do this:
<?php if(false != isset($content->images)): ?>
<pre><?php print_r($content->images); ?></pre>
<?php endif; ?>
But every time I try to skip when I’ve no results (i get a stdClass() empty) I fail. I tried isset, $content->images != NULL, !$content->images… I don’t know how to do it to skip the “Severity: Notice Message: Undefined variable”.
Thank you in advance.
UPDATE:
$content has more sets than images, like $content->_data or $content->title.
When I’ve NO images on database and i’ve no return from MySQL, doing this:
<?php echo count($content->images); ?>
<pre><?php print_r($content->images); ?></pre>
The output is:
1
stdClass ( )
Why can’t you just use
This way your performing checks on both entities.
As images is an object that can be iterated you can also check that.
Also you seem to be using the wrong comparison operators for boolean’s, you should be using the strict standards for comparison, which is
===, and not==, or!==, and not!=🙂