Pregunta

Trying to create an array in a specific format for the google chart API, but im getting an error with the implode function. I found this exmaple but im getting an error with ( ! ) Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\sqltest\sqltester.php on line 22 Line 22 is the implode line, think i may need extra quotes based on what php.net says but I'm doing it wrong.

//Your database query goes here
$list = mysql_query("SELECT city,crimes FROM TABLE");
while($row = mysql_fetch_assoc($list)){
$data[] = "['".$row['city']."', ".$row['crimes']."]";
}

$data_for_chart = implode(",\n"$data);

Looking for an output like this to be used in the google chart api

     ['Cardiff', 300],
     ['London', 900],
     ['Manchester', 500],
     ['Dublin', 400],
     ['Liverpool', 600]
     ]);
¿Fue útil?

Solución

Missing comma here:

$data_for_chart = implode(",\n"$data);
// ---------------------------^

This should be:

$data_for_chart = implode(",\n", $data);

Otros consejos

You are missing comma

$data_for_chart = implode(",\n", $data);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top