Home Forums Chart Support Issues retrievng data from MySql Reply To: Issues retrievng data from MySql

#7511

Sorry again, I could do it, I did a merge between original file and the one proposed by you, and I could get it, but I have the encoding issues anyway you can check it here: http://parles.upf.edu/llocs/adljc/grafics/graf_tipus_recursos.php, this is the resulting file:

tipus_recursos.php

<?php
header('Content-Type: application/json');
$con = mysqli_connect("localhost","dbuser","dbpassword","database");
// Check connection
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to DataBase: " . mysqli_connect_error();
}else
{
    $data_points = array();
    $result = mysqli_query($con, "SELECT <code>Tipus_1</code> AS 'Tipus', COUNT(*) AS 'Recursos' FROM <code>values</code> GROUP BY <code>Tipus_1</code> DESC");
    while($row = mysqli_fetch_array($result))
    {
        $point = array("label" => $row['Tipus'] , "y" => $row['Recursos']);
        array_push($data_points, $point);
    }
//    echo json_encode($data_points, JSON_NUMERIC_CHECK);
        $length = sizeof($data_points);
                echo "[";
                for ( $i = 0; $i <= $length-1; $i++) { 
                        echo "{ \"label\": \"" , $data_points[$i]['label'],"\", \"y\": " , $data_points[$i]['y'], "}";
                        if( $i < $length-1)
                                echo ",";
                }
                echo "]";
}
mysqli_close($con);
?>