Note that there are some explanatory texts on larger screens.

plurals
  1. POSmarty nested for-each with array
    text
    copied!<p>I'm having a little trouble with Smart for-each loops - here's my code:</p> <pre><code>{* this example will print out all the values of the $custid array *} {foreach from=$order_info item=amount} amount: {$amount}&lt;br&gt; {/foreach} </code></pre> <p>So basically I'm just trying to loop through and print the "amount" from $order_info - the problem is, it just prints the whole array and not just the "amount".</p> <p>Here's a reduced number of items from the array that I got from the debug console:</p> <pre><code>{$order_info} Array (86) order_id =&gt; "13" is_parent_order =&gt; "N" parent_order_id =&gt; "0" company_id =&gt; "0" user_id =&gt; "1" total =&gt; "1077.87" subtotal =&gt; "1049.87" discount =&gt; "0.00" subtotal_discount =&gt; "0.00" payment_surcharge =&gt; "0.00" shipping_ids =&gt; "1" shipping_cost =&gt; "28.00" timestamp =&gt; "1352380055" status =&gt; "O" notes =&gt; "" details =&gt; "" promotions =&gt; Array (0) promotion_ids =&gt; "" title =&gt; "" firstname =&gt; "John" lastname =&gt; "Doe" company =&gt; "" b_title =&gt; "" b_firstname =&gt; "John" b_lastname =&gt; "Doe" b_address =&gt; "44 Main street" b_address_2 =&gt; "test" b_city =&gt; "Boston" b_county =&gt; "" b_state =&gt; "MA" b_country =&gt; "US" b_zipcode =&gt; "02134" b_phone =&gt; "" s_title =&gt; "" s_firstname =&gt; "John" s_lastname =&gt; "Doe" s_address =&gt; "44 Main street" s_address_2 =&gt; "test" s_city =&gt; "Boston" s_county =&gt; "" s_state =&gt; "MA" s_country =&gt; "US" s_zipcode =&gt; "02134" s_phone =&gt; "" phone =&gt; "" fax =&gt; "" url =&gt; "" email =&gt; "joe@burford.co.uk" payment_id =&gt; "3" tax_exempt =&gt; "N" lang_code =&gt; "EN" ip_address =&gt; "62.49.144.33" repaid =&gt; "0" validation_code =&gt; "" localization_id =&gt; "0" payment_method =&gt; Array (15) payment_id =&gt; "3" usergroup_ids =&gt; "0" position =&gt; "30" status =&gt; "A" template =&gt; "check.tpl" processor_id =&gt; "0" params =&gt; "" a_surcharge =&gt; "0.000" p_surcharge =&gt; "0.000" localization =&gt; "" payment =&gt; "Check" description =&gt; "Check payment" instructions =&gt; "Type instructions to pay by visiting ..." lang_code =&gt; "EN" processor =&gt; "" fields =&gt; Array (0) items =&gt; Array (2) 2902390881 =&gt; Array (19) item_id =&gt; "2902390881" order_id =&gt; "13" product_id =&gt; "1110" product_code =&gt; "B0002I9OJS" price =&gt; "549.99" amount =&gt; "1" extra =&gt; Array (9) step =&gt; "1" product_options =&gt; Array (0) unlimited_download =&gt; "N" product =&gt; "eMachines T2958 Desktop PC (2.66 GHz ..." company_id =&gt; "0" is_edp =&gt; "N" edp_shipping =&gt; "N" base_price =&gt; "549.99" stored_price =&gt; "N" product =&gt; "eMachines T2958 Desktop PC (2.66 GHz ..." deleted_product =&gt; "" discount =&gt; "0" company_id =&gt; "0" base_price =&gt; "549.99" original_price =&gt; "549.99" cart_id =&gt; "2902390881" tax_value =&gt; "0" subtotal =&gt; "549.99" display_subtotal =&gt; "549.99" shipped_amount =&gt; "0" shipment_amount =&gt; "1" 2278796194 =&gt; Array (19) item_id =&gt; "2278796194" order_id =&gt; "13" product_id =&gt; "1120" product_code =&gt; "B00086HZJA" price =&gt; "499.88" amount =&gt; "1" extra =&gt; Array (9) step =&gt; "1" product_options =&gt; Array (0) unlimited_download =&gt; "N" product =&gt; "HP Pavilion a1000n Desktop PC (Intel ..." company_id =&gt; "0" is_edp =&gt; "N" edp_shipping =&gt; "N" base_price =&gt; "499.88" stored_price =&gt; "N" product =&gt; "HP Pavilion a1000n Desktop PC (Intel ..." deleted_product =&gt; "" discount =&gt; "0" company_id =&gt; "0" base_price =&gt; "499.88" original_price =&gt; "499.88" cart_id =&gt; "2278796194" tax_value =&gt; "0" subtotal =&gt; "499.88" display_subtotal =&gt; "499.88" shipped_amount =&gt; "0" shipment_amount =&gt; "1" </code></pre> <p>So what I'm really trying to do is get the <code>amount</code> from <code>items</code> within <code>$order_info</code> - I tried $order_info.items but this caused the site to crash.</p> <p>Any ideas are much appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload