SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ... Undefined index: ...Why?

    Hello,
    the result of my scripit is a blank page with a error (JpGraph Error In zend1.php#51 Undefined index: ValMedTemp). I'm crazing, please...
    Thank's all...
    Here's the code:

    PHP Code:
    <?php
    require_once("adodb/adodb.inc.php");
    require_once("./jpgraph-1.17/src/jpgraph.php");
    require_once("./jpgraph-1.17/src/jpgraph_bar.php");
    require_once("./jpgraph-1.17/src/jpgraph_line.php");

    // set the directory where images are cached by JpGraph
    $jpgcache = CACHE_DIR;
    $data = array();

    // establish a connect to the database
    $conn = &ADONewConnection('postgres');
    if (!($conn->PConnect('localhost', 'postgres', 'ettore', 'valori09')))
    die("Attenzione - Non posso momentaneamente connettermi al database");

    // $conn->Connect('localhost', 'postgres', 'ettore', 'valori09');
    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

    // make an sql statement to retrieve the data you want
    $sql = <<<EOS
    SELECT ValMedTemp
    FROM ValoriMeteo
    WHERE idIstante>'23453'
    EOS;

    // create a result set by executing your sql over the connection
    $rs = $conn->Execute(trim($sql));

    // iterate over the result set and create $data arrays
    while (!$rs->EOF) {
    $row[] = $rs->fields;
    $data['ValMedTemp'][] = $row['ValMedTemp'];
    $rs->MoveNext();
    }

    // set title and name for the chart
    $title = ' Daily Temperature';
    $graph_name = 'chart.png';

    // set general graph details
    $graph = new graph(450, 300, $graph_name, 0, false);

    // margins, background color, scale and shadow for the whole graph
    $graph->img->SetMargin(50, 30, 30, 80);
    $graph->SetMarginColor('white');
    $graph->SetScale('textlin');
    $graph->SetShadow();

    // set the title and font
    $graph->title->Set($title);
    //$graph->title->SetFont(FF_VERDANA, FS_BOLD, 14);

    // set the y-axis and title it
    $graph->yaxis->SetLabelAngle(0);
    $graph->yaxis->title->Set('C');

    // set the x-axis, labels and title it
    $graph->xaxis->SetLabelAngle(0);

    // set the graph title and font
    $graph->xaxis->title->Set('Time');

    // line1 is the plan data line, green, thick and marked with circles
    $line1 = new LinePlot($data['ValMedTemp']);
    $line1->mark->SetType(MARK_CIRCLE);
    $line1->SetColor('darkolivegreen');
    $line1->SetWeight(3);
    $line1->SetCenter();
    $line1->SetLegend('T');

    // set legend details
    $graph->legend->SetLayout(LEGEND_HOR);
    $graph->legend->Pos(0.52, 0.85, 'center');

    // add the graphs bottom to top
    $graph->Add($line1);

    // output the graph to cache
    $graph->Stroke();

    $page_title = 'Acquisition Data';

    print <<<EOS
    <html>
    <head>
    <title>$page_title</title>
    </head>
    <body>
    <div style="text-align: center">
    <h3>$page_title</h3>
    <img src="{$jpgcache}{$graph_name}" />
    <p />
    </div>
    </body>
    </html>
    EOS;

    ?>

  2. #2
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $data['ValMedTemp'] is an array which hasn't been predefined outside of the while loop i n which it is used.

    Try: $data = array() before you execute the query or before you enter into the loop.

  3. #3
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put $data = array() before the query and before the loop but the problem is the same.
    What to make? Please!!!!!!!!!!!
    Thanks again

  4. #4
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    PHP Code:
    while (!$rs->EOF) {
    $row $rs->fields;
    $data['ValMedTemp'][] = $row['ValMedTemp'];
    $rs->MoveNext();

    i think $rs->fileds is an array, so what you did with $row[] = $rs->fields, was creating a 2 dimensional array:
    $row[0]['ValMedTemp']

    hth

  5. #5
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Again the same error! But why? I'm crazing....
    I must inizializzare ValMedTemp? And like?

    Ale


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •