Handling Array in PHP

3

I'm creating a PHP that creates graphs using the Google Charts, but i can not supply the function with all data from the array. When I print the function, instead of him print all the states of the array, it only prints the first. I'm doing as follows:

$query = "SELECT estado, count(*) as quantidade FROM tb_participacoes where id_campanha = ". $id_campanha ." GROUP BY estado";

$mostrar = mysql_query($query);

while ($produto = mysql_fetch_array($mostrar)) {
$valores = $produto['estado'];
$referencia = $produto['quantidade'];
}
$grafico = geraGrafico(500, 200, array($valores), array($referencia)) ;
    
asked by anonymous 24.03.2014 / 21:04

2 answers

3

In the% w / w that you have in your code, you always override the value of while and $valores at each iteration, I think you want to use these variables as arrays.

In this case you should use this way (note the $referencia extra in the code):

while ($produto = mysql_fetch_array($mostrar)) {
    $valores[] = $produto['estado'];
    $referencia[] = $produto['quantidade'];
}
    
24.03.2014 / 21:11
0
___ erkimt ___ Handling Array in PHP ______ qstntxt ___

I'm creating a PHP that creates graphs using the Google Charts, but i can not supply the function with all data from the array. When I print the function, instead of him print all the states of the array, it only prints the first. I'm doing as follows:

$grafico = geraGrafico(500, 200, $valores, $referencia);
    
______ azszpr10371 ___

In the% w / w that you have in your code, you always override the value of %code% and %code% at each iteration, I think you want to use these variables as arrays.

In this case you should use this way (note the %code% extra in the code):

$grafico = geraGrafico(500, 200, $valores, $referencia);
    
______ ___ azszpr10372

As Sergio mentioned, use [] in the values and reference variables. Then, when calling the graph, pass the array:

%pre%     
___
24.03.2014 / 21:18