Welcome Guest, Not a member yet? Register   Sign In
Add to object in loop

This maybe be a stupid question, but I'm going through a look and doing some calculations and I'm having trouble adding the final result to the object.

foreach ($parts as $part) {
            $open = new Mo();
            $open->select_sum('quantity')->where('ordertype', 'FG')->where('part_id', $part->id)->group_by('part_id')->get();
            $part->open = $open->quantity;
            //echo $part->open;

If I echo $open->quantity;, I get the result I'm after, but not from $part->open;. I'd like it to be part of the object, so when it's passed to the view, it's available for display.

What am I doing wrong?

Foreach creates a copy, use & to assign reference rather than copying the value.

foreach($parts as &$part) {

I should've add that $parts is an object, so that doesn't seem to work.


Theme © iAndrew 2016 - Forum software by © MyBB