Help! on Annotation Chart creation from Mysql DB and PHP page

531 views
Skip to first unread message

Romain Bernard

unread,
Jul 24, 2014, 8:52:12 AM7/24/14
to google-visua...@googlegroups.com

Hi Everyone,

First of all, I'd like to thank you all for being so helpful!

Here is my concern. I'm trying to build an PHP page that render a Annotation chart from a query done on a Mysql DB.

I tried many examples found in the forums to make an annotation chart working, but I miserably fail to have it working...

I always get this error, and even if mysql_num_rows() is deprecated, I cannot find a way to have it replaced

Warning: mysql_num_rows() expects parameter 1 to be resource, object given in /Applications/XAMPP/xamppfiles/htdocs/server1/Result_console4.php on line 11

Is anyone able to provide me some help ?


Thanks a lot!

Romain

Here is the entire code of my php page.

<?php

//DB connection parameters

require_once("mysql_connect.php");


$result = mysqli_query($con,"select date,value1,value2 from DATABASE");


if ($result !== false) {

$num=mysql_num_rows($result);

$i=0;

echo"";


$output = Array();

while ($i < $num) {

    $DateTimeArray=explode(' ', mysql_result($result,$i,"date"));

    $MYvalue1=mysql_result($result,$i,"value1");

    $MYvalue2=mysql_result($result,$i,"value2");

    

    $dateArray = explode('-', $DateTimeArray[0]);

    $year = $dateArray[0];

    $month = $dateArray[1] - 1; // adjust for javascript's 0-indexed months

    $day = $dateArray[2];

    

    $timeArray = explode(':', $DateTimeArray[1]);

    $hours = $timeArray[0];

    $minutes = $timeArray[1];

    $seconds = $timeArray[2];

    

    $output[] = "[new Date($year, $month, $day, $hours, $minutes, $seconds), $MYvalue1, $MYvalue2]";

    $i++;

}

}


?>



<html>

  <head>

  </head>

      <script type='text/javascript' src='http://www.google.com/jsapi'></script>

    <script type='text/javascript'>

      google.load('visualization', '1.1', {'packages':['annotationchart']});

      google.setOnLoadCallback(drawChart);

      function drawChart() {

        var data = new google.visualization.DataTable();

        data.addColumn('datetime', 'Date');

        data.addColumn('number', 'value1');

        data.addColumn('number', 'value2');

        data.addRows([ <?php echo implode(',', $output); ?>]);


        var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));


        var options = {

          displayAnnotations: true,

        };


        chart.draw(data, options);

      }

    </script>


  <body>

  

  Graph should be here.

  

    <div id='chart_div' style='width: 900px; height: 500px;'></div>

  

  </body>

</html>

Andrew Gallant

unread,
Jul 24, 2014, 2:19:25 PM7/24/14
to google-visua...@googlegroups.com
Did you try my answer to your previous question?

Romain Bernard

unread,
Jul 24, 2014, 5:31:01 PM7/24/14
to google-visua...@googlegroups.com
It works! I did reply you in my previous question

Thanks

Kasper Derkinderen

unread,
Sep 9, 2014, 3:54:03 AM9/9/14
to google-visua...@googlegroups.com
Hi everyone,

Yesterday I played around with google charts. 
It's nice and powerful, buth I had some troubles loading information from my mySQL database.
My files are similar as yours so I post them here hoping somebody can help me out:

html page (with just a few values in data.addRows :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
    <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {'packages':['annotationchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
       data.addColumn('date', 'Date');
       data.addColumn('number', 'Download volume');
       data.addColumn('number', 'Upload volume');
      data.addRows([
          
          // <?php include 'getData.php'; ?> NOT WORKING
          [new Date(2014,09,08), 0, 0],[new Date(2014,09,08), 346, 104]   // just a few > original index.html includes all data
  
   ]);

       var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));

        var options = {
          displayAnnotations: true
        };

        chart.draw(data, options);
      }
    </script>
  </head>

  <body>

Question:
index.html is working. The values in data.addRows are a copy paste of the result of the getData.php (created through the test.php).
index_not_working.html has the include getData.php that creates exactly the same data as the test.php, but the data are not loaded..

I'm quite new in programming and have no clue what's going wrong. 
Anybody any idea what's going wrong?

thanks!

Kasper


Op donderdag 24 juli 2014 14:52:12 UTC+2 schreef Romain Bernard:
getData.php
index_not_working.html
index.html
test.php

Andrew Gallant

unread,
Sep 10, 2014, 8:21:35 PM9/10/14
to google-visua...@googlegroups.com
The problem is because your index file has a .html extension; it should be .php: "index.php".  Your web server will not parse HTML files for PHP code; it just serves them up as-is.
Reply all
Reply to author
Forward
0 new messages