Problems generating correct graphics with php, google charts and Postgresql

0

Currently I am trying to show through a graph the query of a record in postgresql from php but I can only show one of the fields consulted. For example I want to show the total of packages sent by a mail office in total was received by the post office 2275 packages and those were sent 353 when I run the following described only brings me the packages that were received and sent not, without However I run a pg_fetch_assoc to see what data the query is bringing me and it shows me in effect 2275 and 353 but in the pie chart it only brings me one.

<?php

include ("conexion.php");
error_reporting(-1);
ini_set('display_errors', 'On');

$query = "SELECT recibidos, enviados FROM oficina correo WHERE id_envios = '123456'";
$result = pg_query($query);
$result2 = pg_query($query);

//Este paso se muestra correctamente y trae los datos

$felo = pg_fetch_assoc($result2);
echo $felo['recibidos'] . "<br>";
echo $felo['enviados'];
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
        google.charts.load('current', {'packages':['corechart']});
        google.charts.setOnLoadCallback(drawChart);

        function drawChart() {

            var data = google.visualization.arrayToDataTable([
                ['recibidos', 'enviados'],
                <?php
                if($result){
                    while($row = pg_fetch_assoc($result)){
                        echo "['".$row['recibidos']."', ".$row['enviados']."],";
                    }
                }
                ?>
            ]);

            var options = {
                title: 'Estado de los envios',
                width: 900,
                height: 500,
            };

            var chart = new google.visualization.PieChart(document.getElementById('piechart'));

            chart.draw(data, options);
        }
    </script>
</head>
<body>
<!-- Display the pie chart -->
<div id="piechart"></div>
</body>
</html>

I guess the problem must be in the if + while or in the way I show the two fields, but as much as I read I do not see the error so that the two fields are shown in the pie chart, any help will be fine received.

Something similar to this is the result I want to get:

    
asked by Luis Alfredo Serrano Díaz 21.05.2018 в 17:23
source

0 answers