It works, thanks for this quick turn around. Also, I don't know why but my
date format "2014-07-23 20:00:00" was not properly changed, so I had to do
some minor change with the first script I used.
Thanks a million again,
Here is what he looks like:
<?php
//DB connection parameters
require_once("mysql_connect.php");
$result = mysqli_query($con,"select date,value1,value2 from DATABASE");
if ($result !== false) {
$output = Array();
while ($row = mysqli_fetch_assoc($result)) {
$DateTimeArray = $row["date"];
$MYvalue1 = $row["value1"];
$MYvalue2 = $row["value2"];
$date = date('Y-m-d', strtotime($DateTimeArray));
$time = date('H:i:s', strtotime($DateTimeArray));
$dateArray = explode('-', $date);
$year = $dateArray[0];
$month = $dateArray[1] - 1; // adjust for javascript's 0-indexed
months
$day = $dateArray[2];
$timeArray = explode(':', $time);
$hours = $timeArray[0];
$minutes = $timeArray[1];
$seconds = $timeArray[2];
$output[] = "[new Date($year,$month,$day,$hours,$minutes,$seconds),
$MYvalue1, $MYvalue2]";
}
}
?>
Cheers,
Romain
On Thursday, July 24, 2014 1:50:47 AM UTC+2, Andrew Gallant wrote:
>
> You are using mysqli instead of the base mysql library (which is a good
> thing!), so you need to use the mysqli* functions. Try this:
>
> <?php
> //DB connection parameters
> require_once("mysql_connect.php");
>
> $result = mysqli_query($con,"select date,value1,value2 from DATABASE");
>
> if ($result !== false) {
> $output = Array();
> while ($row = mysqli_fetch_assoc($result)) {
> $DateTimeArray = $row["date"];
> $MYvalue1 = $row["value1"];
> $MYvalue2 = $row["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]";
> }
> }
> ?>
>
> On Wednesday, July 23, 2014 11:42:25 AM UTC-4, Romain Bernard wrote:
>>
>> Hi Andrew,
>>
>> I tried all the above example to make an annotation chart working, but I
>> miserably failed 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*
>> Are you able to provide me some help?
>>
>> Hope you can help me..
>> many thanks.
>>
>> Here is my 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>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.