title: sum_array not working in while loop (php, mysql)
body: <p>I have a table with this data</p>
  <pre><code>   ID | name|    num1
      --------------------------
      1  | Marco  | 700
      2  | Alessio| 750
      3  | Luca   | 900
      4  | Mario  | 1200
      5  | Manuel | 700
      6  | Edo    | 1500
  </code></pre>
  <p>Aim is to get an json results that looks like this:</p>
  <pre><code>{&quot;result&quot;:&quot;1&quot;, &quot;data&quot;:[{&quot;name&quot;:&quot;Marco&quot;,&quot;num1&quot;:&quot;700&quot;},{&quot;name&quot;:&quot;Alessio&quot;,&quot;num1&quot;:&quot;750&quot;},{&quot;name&quot;:&quot;Luca&quot;,&quot;num1&quot;:&quot;900&quot;},{&quot;name&quot;:&quot;Mario&quot;,&quot;num1&quot;:&quot;1200&quot;},{&quot;name&quot;:&quot;Manuel&quot;,&quot;num1&quot;:&quot;700&quot;},{&quot;name&quot;:&quot;Edo&quot;,&quot;num1&quot;:&quot;1500&quot;}],&quot;total&quot;:&quot;5.750&quot;}
  </code></pre>
  <p>but the result is this</p>
  <pre><code>{&quot;result&quot;:&quot;1&quot;, &quot;data&quot;:[{&quot;name&quot;:&quot;Marco&quot;,&quot;num1&quot;:&quot;700&quot;},{&quot;name&quot;:&quot;Alessio&quot;,&quot;num1&quot;:&quot;750&quot;},{&quot;name&quot;:&quot;Luca&quot;,&quot;num1&quot;:&quot;900&quot;},{&quot;name&quot;:&quot;Mario&quot;,&quot;num1&quot;:&quot;1200&quot;},{&quot;name&quot;:&quot;Manuel&quot;,&quot;num1&quot;:&quot;700&quot;},{&quot;name&quot;:&quot;Edo&quot;,&quot;num1&quot;:&quot;1500&quot;}],&quot;total&quot;:&quot;700&quot;}
  </code></pre>
  <p>the values ​​are not summed and returns only the first result.</p>
  <p>does anyone have the solution to my problem?
  thank you in advance for your help</p>
  <p>php:</p>
  <pre><code>$stmt = $connection-&gt;prepare(&quot;SELECT GROUP_CONCAT(concat.name) as name, GROUP_CONCAT(concat.num1) as num1 FROM (SELECT name, num1 FROM giocatori WHERE categoria=? ORDER BY RAND() LIMIT 6 )concat&quot;);
  
  $stmt-&gt;bind_param(&quot;s&quot;,$categoria);
  $stmt-&gt;execute();
  $risultato = $stmt-&gt;get_result();
  
  $result=array(&quot;result&quot;=&gt;&quot;1&quot;, &quot;data&quot;=&gt;&quot;&quot; ,&quot;total&quot;=&gt;&quot;&quot;);
  
  while($rispostacarte=$risultato-&gt;fetch_assoc()){
  $valoretotale=array($rispostacarte['num1']);
  $result['total'] = array_sum($valoretotale);
  $result['data']=$rispostacarte;
  $ris = $result[&quot;data&quot;];
  
  $tempRis = [];
  
  foreach ($ris as $key =&gt; $value) {
  $explodedArray = explode(&quot;,&quot;, $value);
  $length = count($explodedArray);
  for ($i=0; $i &lt; $length ; $i++) { 
  $tempRis[$i][$key] = $explodedArray[$i];
  }
  }
  $result[&quot;data&quot;] = $tempRis;
  echo json_encode($result);  
  }
  </code></pre>