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

[eluser]frist44[/eluser]
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.

Code:
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?
#2

[eluser]danmontgomery[/eluser]
Foreach creates a copy, use & to assign reference rather than copying the value.

Code:
foreach($parts as &$part) {
#3

[eluser]frist44[/eluser]
I should've add that $parts is an object, so that doesn't seem to work.
#4

[eluser]frist44[/eluser]
nothing?




Theme © iAndrew 2016 - Forum software by © MyBB