Adding records separated by commas - PHP + MYSQL

1

In the mysql database I have the following table:

Notethatthecolumnfieldisinjsonformat.Ihavemultiplerecordsinasinglefield.Ineedascripttocounteachrecordseparatedbycommasandaddandassigntoavariable.Inthiscasethevariablewouldbesetto6.

InthecodebelowIgetthenumberofrecordsperline,butI'mnotabletodothesum.

$conexao=mysqli_connect('localhost','root','');$banco=mysqli_select_db($conexao,'movement');mysqli_set_charset($conexao,'utf8');$res=mysqli_query($conexao,"SELECT coluna FROM tabela");

while($r = mysqli_fetch_assoc($res)) {

      echo count(json_decode($r['coluna'], true));      
}
    
asked by anonymous 07.10.2018 / 23:06

1 answer

0

No while adding the results and outside it, present the result:

while($r = mysqli_fetch_assoc($res)) {

      $count += count(json_decode($r['coluna'], true));      
}        

 echo  $count; 
    
07.10.2018 / 23:31