Error importing records from database to chart

Asked

Viewed 35 times

0

In my old system I had a hightcharts chart that imports the record values of my database table, however, when using the same model in another system, the following error started to appear:

Notice: Undefined index: Scjan in C: Program Files (x86) Easyphp5.2.10 www Sis_tam indicadorS.php

Notice: Undefined index: Sdjan in C: Program Files (x86) Easyphp5.2.10 www Sis_tam indicadorS.php

Notice: Undefined index: Sejan in C: Program Files (x86) Easyphp5.2.10 www Sis_tam indicadorS.php

Follow the code of my graphic page:

php part responsible for making the import:

    <script src="../../code/modules/series-label.js"></script>
    <script src="../../code/modules/exporting.js"></script>

    <div id="container"></div>
    <?php
    /*-------------------------------------Janeiro ---------------------------------*/
    require_once("strcon.php");
    $totaSAJ = 0;
    $totaSBJ = 0;
    $totaSCJ = 0;
    $totaSDJ = 0;
    $totaSEJ = 0;

    $SAJ = "SELECT COUNT(ID) AS SAJan FROM pedidos WHERE SERVICO = 'Serviço A' and MES = 'JAN' and ANO = '2018'";
    $SBJ = "SELECT COUNT(ID) AS SBJan FROM pedidos WHERE SERVICO = 'Serviço B' and MES = 'JAN' and ANO = '2018'";
    $SCJ = "SELECT COUNT(ID) AS SCJan FROM pedidos WHERE SERVICO = 'Serviço C' and MES = 'JAN' and ANO = '2018'";
    $SDJ = "SELECT COUNT(ID) AS SDJan FROM pedidos WHERE SERVICO = 'Serviço D' and MES = 'JAN' and ANO = '2018'";
    $SEJ = "SELECT COUNT(ID) AS SEJan FROM pedidos WHERE SERVICO = 'Serviço E' and MES = 'JAN' and ANO = '2018'";
    
    $consultasaj = mysqli_query($strcon, "SELECT COUNT(ID) AS SAJan FROM pedidos WHERE SERVICO = 'Serviço A' and MES = 'JAN' and ANO = '2018'");
    $consultasbj = mysqli_query($strcon, "SELECT COUNT(ID) AS SBJan FROM pedidos WHERE SERVICO = 'Serviço B' and MES = 'JAN' and ANO = '2018'");
    $consultascj = mysqli_query($strcon, "SELECT COUNT(ID) AS SCJan FROM pedidos WHERE SERVICO = 'Serviço C' and MES = 'JAN' and ANO = '2018'");
    $consultasdj = mysqli_query($strcon, "SELECT COUNT(ID) AS SDJan FROM pedidos WHERE SERVICO = 'Serviço D' and MES = 'JAN' and ANO = '2018'");
    $consultasej = mysqli_query($strcon, "SELECT COUNT(ID) AS SEJan FROM pedidos WHERE SERVICO = 'Serviço E' and MES = 'JAN' and ANO = '2018'");

    if ($consultasaj = mysqli_query($strcon, $SAJ)) {
        if ($rowsaj = mysqli_fetch_assoc($consultasaj)) {
            $totaSAJ = $rowsaj['SAJan']; //Seta o total
        }
        mysqli_free_result($consultasaj);
    } else {

    }
    if ($consultasbj = mysqli_query($strcon, $SBJ)) {
        if ($rowsbj = mysqli_fetch_assoc($consultasbj)) {
            $totaSBJ = $rowsbj['SBJan']; //Seta o total
        }
        mysqli_free_result($consultasbj);
    } else {

    }
    if ($consultascj = mysqli_query($strcon, $SCJ)) {
        if ($rowscj = mysqli_fetch_assoc($consultascj)) {
            $totaSCJ = $rowsbj['SCJan']; //Seta o total
        }
        mysqli_free_result($consultascj);
    } else {

    }
    if ($consultasdj = mysqli_query($strcon, $SDJ)) {
        if ($rowsdj = mysqli_fetch_assoc($consultasdj)) {
            $totaSDJ = $rowsbj['SDJan']; //Seta o total
        }
        mysqli_free_result($consultasdj);
    } else {

    }
    if ($consultasej = mysqli_query($strcon, $SEJ)) {
        if ($rowsej = mysqli_fetch_assoc($consultasej)) {
            $totaSEJ = $rowsbj['SEJan']; //Seta o total
        }
        mysqli_free_result($consultasej);
    } else {

    }
    

Party responsible for the chart:

<script type="text/javascript">

        Highcharts.chart('container', {

            title: {
                text: 'Indicador anual de serviços'
            },

            subtitle: {
                text: ''
            },
            xAxis: [{
                categories: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun',
                    'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
                crosshair: true
            }],

            yAxis: {
                title: {
                    text: ''
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle'
            },


            series: [{
                name: 'Serviço A',
                data: [<?php echo $rowsaj['SAJan'];?>, <?php echo $rowsaf['SAFev'];?>,<?php echo $rowsamar['SAMar'];?>, <?php echo $rowsaabr['SAAbr'];?>, <?php echo $rowsamai['SAMai'];?>, <?php echo $rowsajun['SAJun'];?>, <?php echo $rowsajul['SAJul'];?>, <?php echo $rowsaago['SAAgo'];?>, <?php echo $rowsaset['SASet'];?>, <?php echo $rowsaout['SAOut'];?>, <?php echo $rowsanov['SANov'];?>, <?php echo $rowsadez['SADez'];?>]
            }, {
                name: 'Serviço B',
                data: [<?php echo $rowsbj['SBJan'];?>,<?php echo $rowsbf['SBFev'];?>, <?php echo $rowsbmar['SBMar'];?>, <?php echo $rowsbabr['SBAbr'];?>, <?php echo $rowsbmai['SBMai'];?>, <?php echo $rowsbjun['SBJun'];?>,<?php echo $rowsbjul['SBJul'];?>, <?php echo $rowsbago['SBAgo'];?>, <?php echo $rowsbset['SBSet'];?>, <?php echo $rowsbout['SBOut'];?>, <?php echo $rowsbnov['SBNov'];?>, <?php echo $rowsbdez['SBDez'];?>]
            }, {
                name: 'Serviço C',
                data: [<?php echo $rowscj['SCJan'];?>, <?php echo $rowscf['SCFev'];?>, <?php echo $rowscmar['SCMar'];?>, <?php echo $rowscabr['SCAbr'];?>, <?php echo $rowscmai['SCMai'];?>, <?php echo $rowscjun['SCJun'];?>, <?php echo $rowscjul['SCJul'];?>, <?php echo $rowscago['SCAgo'];?>, <?php echo $rowscset['SCSet'];?>, <?php echo $rowscout['SCOut'];?>, <?php echo $rowscnov['SCNov'];?>, <?php echo $rowscdez['SCDez'];?>]
            }, {
                name: 'Serviço D',
                data: [<?php echo $rowsdj['SDJan'];?>, <?php echo $rowsdf['SDFev'];?>, <?php echo $rowsdmar['SDMar'];?>, <?php echo $rowsdabr['SDAbr'];?>, <?php echo $rowsdmai['SDMai'];?>, <?php echo $rowsdjun['SDJun'];?>, <?php echo $rowsdjul['SDJul'];?>, <?php echo $rowsdago['SDAgo'];?>, <?php echo $rowsdset['SDSet'];?>,<?php echo $rowsdout['SDOut'];?>, <?php echo $rowsdnov['SDNov'];?>, <?php echo $rowsddez['SDDez'];?>]
            }, {
                name: 'Serviço E',
                data: [<?php echo $rowsej['SEJan'];?>, <?php echo $rowsef['SEFev'];?>, <?php echo $rowsemar['SEMar'];?>, <?php echo $rowseabr['SEAbr'];?>, <?php echo $rowsemai['SEMai'];?>, <?php echo $rowsejun['SEJun'];?>,<?php echo $rowsejul['SEJul'];?>,<?php echo $rowseago['SEAgo'];?>, <?php echo $rowseset['SESet'];?>, <?php echo $rowseout['SEOut'];?>, <?php echo $rowsenov['SENov'];?>, <?php echo $rowsedez['SEDez'];?>]
            }],

            responsive: {
                rules: [{
                    condition: {
                        tickInterval: 1,
                    },
                    chartOptions: {
                        legend: {
                            layout: 'horizontal',
                            align: 'center',
                            verticalAlign: 'bottom'
                        }
                    }
                }]
            }

        });
        </script>

THE LINES THAT MAKE A MISTAKE ARE:

$totaSCJ = $rowsbj['Scjan'];

$totaSDJ = $rowsbj['Sdjan'];

$totaSEJ = $rowsbj['Sejan'];

NOTE: I made a code the same as the month of January for the other months, so more months appear on the chart, but as they all give the same error only I found necessary to put the code of one of the months to facilitate the understanding.

I really need to solve this problem today still, so if you could help me I would be very grateful. :)

-------------------------------- UPDATING -------------------------------

ALL MISTAKES WERE SOLVED WHEN I PLACED AN ISSET BEFORE THE $ROW $totaSCJ = ISSET($rowsbj['SCJan']); BUT STILL THE GRAPH DOESN’T APPEAR ON THE SCREEN.

  • mariana puts values that do not come from the database in these variables, and you can already map where the error is. I don’t think anything’s coming

  • All errors solved when I put an ISSET before the Row, but still the graph does not appear

  • have checked whether data is coming from these variables?

  • No. But even when I leave the chart without php, the chart I was opening before does not open.

  • vem pro chat [link] (https://chat.stackexchange.com/rooms/11910/batteryoverflow)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.