I have a function that has a query and a foreach loop:
$sql = "SELECT * FROM explore WHERE id = $id";
$object = $this->db->select($sql);
foreach($object as $val){
$results = array('id'=>$val->id, 'from_id'=>$val->from_id);
$this->result[] = $this->notify($results);
}
return $results;
The issue here is that if I return $object I get 2 records:
Array
(
[0] => stdClass Object
(
[from_id] => 6
[id] => 3
)
[1] => stdClass Object
(
[from_id] => 6
[id] => 1
)
)
and return $results has 1 record:
Array
(
[id] => 1
[from_id] => 6
)
Also if I return $this->result;, $this->result[] = $this->notify($results); does run twice but uses the same record twice returned by $results instead of using the 2 records from $object
Hope you guys can understand my issue.
ps: I am using the zend framework
Any ideas?
Edit: notify is a function in another class
$getResultsisn’t being set anywhere in your code, visibly. It looks like you ought to be returning$this->resultinstead, as that’s where the results are being stored. That’s my best guess given the amount of code you’ve given us. If you can provide more code, I can further update my answer if it doesn’t work for you.Given your comment, update your code to this:
If you’re only returning
$results, it’ll be filled with the last item, not every item.