Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>php script</p> <pre><code>&lt;pre&gt; &lt;?php // Data Source $db_data = array( array('manufacturers_id' =&gt; 1, 'manufacturers_name' =&gt; 'Some Company', 'products_price' =&gt; 1.99, 'products_quantity' =&gt; 12, 'products_cost' =&gt; 0.49), array('manufacturers_id' =&gt; 1, 'manufacturers_name' =&gt; 'Some Company', 'products_price' =&gt; 1.99, 'products_quantity' =&gt; 12, 'products_cost' =&gt; 0.49), array('manufacturers_id' =&gt; 2, 'manufacturers_name' =&gt; 'Another Company', 'products_price' =&gt; 12.99, 'products_quantity' =&gt; 112, 'products_cost' =&gt; 10.49), array('manufacturers_id' =&gt; 2, 'manufacturers_name' =&gt; 'Another Company', 'products_price' =&gt; 12.99, 'products_quantity' =&gt; 112, 'products_cost' =&gt; 10.49), ); // Sort Data $db_data_sorted = array(); foreach ($db_data as $data) { $db_data_sorted[$data['manufacturers_id']][$data['manufacturers_name']]['brands_total_sales'] += (intval($data['products_quantity']) * floatval($data['products_price'])); $db_data_sorted[$data['manufacturers_id']][$data['manufacturers_name']]['products'][] = array( 'products_price' =&gt; $data['products_price'], 'products_quantity' =&gt; $data['products_quantity'], 'products_cost' =&gt; $data['products_cost'] ); } // Debug print_r($db_data_sorted); ?&gt; </code></pre> <p>output:</p> <pre><code>Array ( [1] =&gt; Array ( [Some Company] =&gt; Array ( [brands_total_sales] =&gt; 47.76 [products] =&gt; Array ( [0] =&gt; Array ( [products_price] =&gt; 1.99 [products_quantity] =&gt; 12 [products_cost] =&gt; 0.49 ) [1] =&gt; Array ( [products_price] =&gt; 1.99 [products_quantity] =&gt; 12 [products_cost] =&gt; 0.49 ) ) ) ) [2] =&gt; Array ( [Another Company] =&gt; Array ( [brands_total_sales] =&gt; 2909.76 [products] =&gt; Array ( [0] =&gt; Array ( [products_price] =&gt; 12.99 [products_quantity] =&gt; 112 [products_cost] =&gt; 10.49 ) [1] =&gt; Array ( [products_price] =&gt; 12.99 [products_quantity] =&gt; 112 [products_cost] =&gt; 10.49 ) ) ) ) ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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