Marcial Cahuaya Asked: 2020-12-23 13:37:04 +0800 CST 2020-12-23 13:37:04 +0800 CST 2020-12-23 13:37:04 +0800 CST Count positions of a SQL field 772 How do I manage to count each position of this array? I was working with SQL queries, what happens is that I can't get the positions . php 2 Answers Voted Best Answer J.Correa 2020-12-23T14:19:14+08:002020-12-23T14:19:14+08:00 You can query it normally and then use the native Php function called explode $query = "SELECT `resultados` FROM tabla"; After you get the query, you apply explode: $result = $conn->query($query); $result = $result->fetch_array(MYSQLI_ASSOC); // Obtengo un array con cada elemento separado por paid ("|") $resultados = explode('|', $result); $cantidad_resultados = count($resultados); See the explode documentation for better understanding. Omar Barrera Valentin 2020-12-23T13:44:41+08:002020-12-23T13:44:41+08:00 If what you need is to perform the sum from your SQL, you can try SELECT SUM((LEN(campo] ) - LEN(REPLACE(campo, 'RAISERROR 50000', '')))/LEN('RAISERROR 50000')) as suma FROM table But if what you need is to do it from your PHP You can use: str_word_count() Example: $cadena = "Esto es una prueba para contar palabras"; echo "$cadena"; // get the number of words with the parameter '0' echo "Hay ".str_word_count($cadena, 0). " palabras en la cadena '$cadena'"; // store the words in an array $array_cadena = str_word_count($cadena, 1); // get each element from the array foreach ($array_cadena as $palabra) { echo $palabra . " "; }
You can query it normally and then use the native Php function called explode
After you get the query, you apply explode:
See the explode documentation for better understanding.
If what you need is to perform the sum from your SQL, you can try
But if what you need is to do it from your PHP
You can use:
Example:
// get the number of words with the parameter '0'
// store the words in an array
// get each element from the array