0

Hi i have 2 arrays returned from a controller.

$order

array (size=2)
  0 => 
    array (size=2)
      'orderid' => int 1
      'ostatus' => string 'Placed' (length=6)
  1 => 
    array (size=2)
      'orderid' => int 4
      'ostatus' => string 'Placed' (length=6)

$orderdetails

array (size=2)
  1 => 
    array (size=3)
      0 => 
        array (size=3)
          'oid' => int 1
          'img6_path' => string 'images/product-list/pro1-list.jpg' (length=33)
          'brand_name' => string 'Puma' (length=4)
      1 => 
        array (size=3)
          'oid' => int 1
          'img6_path' => string 'images/product-list/pro2-list.jpg' (length=33)
          'brand_name' => string 'DressBerry' (length=10)    
      2 => 
        array (size=3)
          'oid' => int 1
          'img6_path' => string 'images/product-list/pro3-list.jpg' (length=33)
          'brand_name' => string 'United Colors of Benetton' (length=25)
  4 => 
    array (size=1)
      0 => 
        array (size=2)
          'oid' => int 4
          'img6_path' => string 'images/product-list/pro4-list.jpg' (length=33)
          'brand_name' => string 'Puma' (length=4)

I am trying to print it in this order:

enter image description here

This is what i have been doing:

foreach($order as $ord)
  //printing order id
foreach($orderdetail as $od)
foreach($od as $x)
  //printing the products
endforeach()
endforeach()
endforeach()

But this is printing

  • orderid 1 with 3 products
  • orderid 1 with 1 product (That belonged to orderid 4)
  • orderid 4 with 3 products (That belonged to orderid 1)
  • orderid 4 with 1 product

Can anyone tell me how should i loop through the array so that after printing the first 3 products in order1 the loop breaks out and then print the 1 product in order 4 (Like in the picture above). Thanks

1
  • create join query for controller Commented Feb 19, 2015 at 12:45

1 Answer 1

1
@foreach($order as $ord)
  //printing order id
    @foreach($orderdetail[$ord->orderid] as $od)
        @foreach($od as $x)
            //printing the products
        @endforeach
    @endforeach
@endforeach

where @foreach($orderdetail[$ord->orderid] as $od) is the big change... I would give this a try...

Sign up to request clarification or add additional context in comments.

1 Comment

@8yt3c0d3 In case this solved your issue, would you mind giving the answer the grean check? Kind of hunting for reputation here :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.