Pass a php array in a query and return multiple results [closed]

1

I want to pass a POST dynamic array of type:

array(2) { [0]=> string(1) "1" [1]=> string(1) "3" }

For an SQL query that returns multiple results depending on the string values in the array

Select nome, count(avaliacao) FROM tabela WHERE '1'
Select nome, count(avaliacao) FROM tabela WHERE '2'

And the result of the query will be:

  

Array (2) ([result 1] = > 10, [result 2] = > 13)

I have already tried with implode and SQL IN but returns only the total of count of 1 and 3.

    
asked by anonymous 27.09.2017 / 10:49

1 answer

2

I believe you should change the query to only perform one query and bring all the results you need.

Another detail is missing the name of the column there in the where, but I will consider that you forgot to only put in the question here. Try this:

SELECT 
    nome, count(avaliacao) 
FROM 
    tabela 
WHERE 
    nomeColuna in('1','2') 
GROUP BY 
    nome;
    
27.09.2017 / 14:51