Add comma-separated records - PHP + MYSQL

Asked

Viewed 141 times

0

In mysql database I have the following table:

inserir a descrição da imagem aqui

Note that the column field is in json format. I have several records in a single field. I need a script to count each record separated by comma and add and assign it to a variable. In this case the variable would be set to 6.

In the code below I get the amount of records per line, but I’m not able to make the sum.

$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));      
}

1 answer

0


No while add the results and outside it present the result:

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

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

 echo  $count; 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.