Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:41:40+00:00 2026-05-27T18:41:40+00:00

I have php-page retrieving sqlight-data. The lower part is the important in which I

  • 0

I have php-page retrieving sqlight-data.
The lower part is the important in which I prepared it for Flot graph plotting (unix epoch timestamp as time series data in an array).
What am I doing wrong? Please advice.

echo json_encode($dataset1) in php part

gives:

[1320710855000,44][1320711755000,46][1320712655000,44][1320713555000,42][1320714456000,56]..
and Chromes Resources show:

script type=”text/javascript”>
var kurve = [1320774758000,72];

<?php
 error_reporting(E_ALL);
 try {
    /*** DB erstellen ***/
    $dbh = new PDO('sqlite:/var/www/zaehler/inc/db/zaehler.sqlite');
    /*** set all errors to excptions ***/
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $startdate=startdate();
    $sql = "SELECT date FROM energielog ORDER BY OID DESC LIMIT 1";
    $result = $dbh->query($sql);
    foreach($result as $row) {
          if ($row['date']!=$startdate) {
              $startdate=$row['date'];
                  }
          }
    $sql = "SELECT kwh, peak, OID, date, time FROM energielog WHERE date >=".$startdate." ORDER BY OID ASC";
    $result = $dbh->query($sql);

    foreach($result as $row) {                
            $oid=$row['OID']-1;
            $sql2 = "SELECT kwh FROM energielog WHERE oid <".$oid." ORDER BY OID DESC LIMIT 1";
            $result2 = $dbh->query($sql2);
            foreach($result2 as $row2) {
                    $letzter_eintrag=str_replace(",",".",$row2['kwh']);
                    }
                    $aktueller_eintrag=str_replace(",",".",$row['kwh']);
                    $eintrag=round(($aktueller_eintrag-$letzter_eintrag)*1000/0.5,0);
                    $peak=$row['peak']*1000;                       
                    $time=str_pad($row['time'],6,'0',STR_PAD_LEFT);
                    $times=substr($time,0,2).":".substr($time,2,2);                       
                    $timeStamp=mktime(
                    substr($time,0,2),
                    substr($time,2,2),
                    substr($time,4,2),
                    substr($startdate,2,2),
                    substr($startdate,4,2),
                    substr($startdate,0,2)
                    );                        
                   $dataset1 = array(($timeStamp)*1000, $eintrag);                       
                   echo json_encode($dataset1);
            }
}
catch(Exception $e)
{
    echo $e->getMessage();
    die();
}   
?>  
<div id="placeholder" style="width:600px;height:300px;"></div>
<script type="text/javascript">

var kurve = <?php echo json_encode($dataset1); ?>;

$(function () {    
$.plot($("#placeholder"), [kurve], { xaxis: { mode: "time",  timeformat: "%y/%m/%d/%H:%M"} });    
});
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:41:40+00:00Added an answer on May 27, 2026 at 6:41 pm

    Looking at this real quick a couple of things jump out at me.

    One:

    var kurve = "<?php echo json_encode($dataset1); ?>";
    

    You do not want the " around the PHP. This will cause the kurve var to a be string not an array of arrays.

    Two:

    [1320710855000,44][1320711755000,46][1320712655000,44][1320713555000,42][1320714456000,56]
    

    Did you or the echo drop the , between each array point? This would not be valid JS syntax.

    EDITS

    I see it now. dataset1 is being re-declared on each loop. You want:

    $dataset1 = array();
    foreach($result as $row) {
      <do your processing..?
      array_push($dataset1, array(($timeStamp)*1000, $eintrag));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP page and I want to share some data between pages
I have a php page which contains a form. Sometimes this page is submitted
i have a php page.Now i need to post data from this php page
I have a php page which dynamically produces this; ... <select name='sales_id'> <option> <option
i have a category drop down combo in my php page which shows categories
I have a php page that displays rows from a mysql db as a
I have a php page and i have some javascript code to have a
I have a PHP page I need to limit execution access of to only
I have a PHP page that returns a piece of HTML to set the
I have a PHP page, in Wordpress. When I add a inline Thickbox to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.