1
I want to pass a dynamic POST array of type:
array(2) { [0]=> string(1) "1" [1]=> string(1) "3" }
For an SQL query where it 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’ve tried with the implode
and SQL IN
but returns only the total of count
of 1 and 3.
You should think of a writing logic of the sql line, to concatenate all the values of the array
– Renato Junior
Possible duplicate of How to run the same query for different "ids"
– Francisco
@Francisco, what I want is a little different. I want a query for each result... I have already used SQL IN and the result is Count 1 and 3, not Count 1 and Count 3.
– Christophe Costa
It’s very poorly explained, I can’t understand what you want... Explain why you want to do this.
– Francisco
@Francisco I want to build graph from the multiple information selected in the form I have behind.
– Christophe Costa
The
IN
seems to be quite feasible for you. If you are in doubt, see that example.– Francisco
Also I can only see the
in
as a solution, then I think it will be better if you edit the question and add the table structure, examples of records present in it and what the expected result would be. As it stands, the question is not clear enough.– Woss
Also try to group the query by the relevant fields. Ex:
Select nome, count(avaliacao) FROM tabela WHERE id IN (1,2,5,10) GROUP BY nome
– rray
@rray his answer, already changed the panorama and showed almost an approximation of the expected result. It lacks the hierarchy of grandchildren until the grandmother. Because in IN is a variable that various values and I want to return the value of them. The problem is that a table has the definition of the hierarchy of the grandmother up to the children and grandchildren. And on the other you have the count for the final result for the corresponding id. This id is the id corresponding to the one entered in db.
– Christophe Costa