Menu

Invalid data array (row 0)

2016-01-25
2016-01-25
  • Paulo Cesar

    Paulo Cesar - 2016-01-25

    Arq graphics.php

    <?php
        $num_linha = 0;
            $unidade_total = 0;  $grafic_dados = "array( ";  $grafic_legenda = 'array(';
            while ($row = hesk_dbFetchAssoc($res))
            {
                if ($num_linha != 0) { $grafic_dados.=", "; $grafic_legenda.= ", "; }
                $cls = $cls ? '' : 'style="background:#EEEEE8;"';
                if ($row['custom3'] == '') { $nom_unidade = 'NAO PREENCHIDO'; } else { $nom_unidade = $row['custom3']; }
                $qtd_unidade = $row['total'];  $unidade_total += $row['total'];
                echo "<tr $cls><td>$nom_unidade</td><td>$qtd_unidade</td></tr>";
                $grafic_dados.= "array('$nom_unidade', $qtd_unidade)";
                $grafic_legenda.= "'$nom_unidade'";
                $num_linha ++;
            }
            $grafic_dados.=")";  $grafic_titulo = "CHAMADOS POR MODULOS";  $grafic_legenda.=")";
    
    echo "<img src=\"grafics2.php?dados=$grafic_dados&titulo=$grafic_titulo&legenda=$grafic_legenda\"/>";
    ?>
    

    Arq grafics2.php

    <?php
    
    $recebe_dados = $_GET["dados"];
    $recebe_titulo = $_GET["titulo"];
    $recebe_legenda = $_GET["legenda"];
    
    require_once 'phplot-6.2.0/phplot.php';    
    
    $plot = new PHPlot(500 , 350);   
    
    $plot->SetTitle($recebe_titulo);
    $plot->SetPrecisionY(1);
    $plot->SetPlotType("bars");
    $plot->SetDataType("text-data");
    $plot->SetDataValues($data);
    $plot->SetXTickPos('none');
    $plot->SetXLabel("Fonte: Teste by Paulo");
    $plot->SetXLabelFontSize(2);
    $plot->SetAxisFontSize(2);
    $plot->SetYDataLabelPos('plotin');
    
    $plot->DrawGraph();
    ?>
    
     

    Last edit: lbayuk 2016-01-25
  • lbayuk

    lbayuk - 2016-01-25

    Hello,

    Sorry I am unable to reply in Portuguese, but I hope this will help you.

    The first thing I see is that your second script receives the data array as $recebe_dados (using the 'dados' (data) URL parameter), but then you are using a different variable $data in SetDataValues(). This will not work.

    But I think you have a bigger problem than that. You are building a string representation of a PHP array in your first script for $grafic_dados, then trying to pass that as a URL parameter, and expecting the script to receive it and turn it into a PHP array. That isn't going to work.

    The second script is going to get a string like this: "array(array('...', ...)...)" which won't become an array in your second script. Also any such parameter must be URL-encoded before being used in a URL in case it has special characters.

    I think what you need to do is: Your first script should build a proper PHP array for the data (not a string). Then use either: serialize() or json_encode() to turn it into a string representation. Then use urlencode() on the result, to get a string which is safe to pass as a URL parameter.

    In the receiving script, use urldecode() first, then use the corresponding unserialize() or json_decode() to turn the result back in to a PHP array.

    An alternative to passing data arrays like this is to use session variables, especially if your script is already set up to use PHP sessions.

    I hope this is understandable and helps.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.