title: Collect values from DB, group matching values, count it and use in other code
body: <p>This is what my <code>customers_basket</code> table looks like:</p>
  
  <pre><code>customers_id | products_id                         | basket_quantity
  3            | 56:3121fefbe6043d6fc12e3b3de2c8fc38 | 3
  3            | 56:fb4c9278fcfe6225b58c06711a7e62ef | 1
  3            | 56:8e334fce09556108f5416e27154b6c27 | 1
  3            | 52:f3b9f38e4ddd18035bc04cd264b0f052 | 1
  </code></pre>
  
  <p>This is the query I'm using:</p>
  
  <pre><code>$products_in_cart_query = "SELECT products_id FROM customers_basket WHERE customers_id = " . $_SESSION['customer_id'] ."";
  $products_in_cart       = $db-&gt;Execute($products_in_cart_query);
  $products_in_cart_model = $products_in_cart-&gt;fields['products_id'];
  $products_in_cart_model = substr($products_in_cart_model, 0, strpos($products_in_cart_model, ":"));
  </code></pre>
  
  <p>The end result I get is 56,56,56,52</p>
  
  <p>First of all, how do I use the first line's quantity field? I'd need to list that products_id 3 times since quantity is 3. Therefore, the end result needs to be: 56,56,56,56,56,52
  or, for easier understanding (56,56,56),56,56,52</p>
  
  <p>And second, how do I count how many same values I have? In this case, I have 5x56 and 1x52. I need to use those counts in my further calculation.</p>
  
  <p>EDIT: further calculations explained
  I need to know how many of each product_id I have and then run something like this:</p>
  
  <pre><code>foreach(product_id) {
      $shipping_cost += FIXED_VALUE * basket_qty;
  }
  </code></pre>