1
For styling a web page, I usually use highchart charts with information from a mysql database via php. For those who are not familiar with highcharts, here is a simple code example.
Highcharts.chart('minhadiv', {
chart: {
type: 'bar'
},
xAxis: {
categories: ['Categoria 1', 'Categoria 2', 'Categoria 3'],
},
series: [{
name: 'Informação',
data: [1, 2, 3]
}]
});
This code returns me a graph like this:
I always make the php connection to mysql within the field data
, succeeding.
Below follows the example of an sql connection I’ve used before:
data: [<?php
$mysqli = new mysqli('servidor', 'usuario', 'senha', 'banco');
$sql = $mysqli->query("SELECT minhacoluna from minhatabela");
?>
<?php while ($result = mysqli_fetch_array($sql)) {?>
<?php echo $result["minhacoluna"]?>,
<?php } ?>],
The problem is that now I needed to make this sql connection both in the field data
how much on the field categories
, as the categories may change according to my database. When trying to put a php code like the above that I normally use, I got no result. How to proceed in this case?
But your categories continue the ones you manually entered... (Category 1, Category 2 and Category 3). When I tried to get it straight from the database it didn’t work.
– Renata
I changed the code to get the categories of the database... If it doesn’t work, post the error so we can help you precisely..
– Piupz