J.Did
J.Did

Reputation: 1

Highchart basic-line

http://www.highcharts.com/stock/demo/basic-line My code for json.php:

<?php
header("content-type: application/json");
define('HOST', 'localhost');
     define('USER', 'root');
     define('PASSWORD', 'Super_Password');
     define('NAME_BD', 'bd');
$connect = mysql_connect(HOST, USER, PASSWORD)
        or die("error"
               .mysql_error( ));
//    print ("no error");
mysql_select_db(NAME_BD, $connect)
         or die ("error"
                 .mysql_error( ));
$result = mysql_query("SELECT UNIX_TIMESTAMP(`Time`) * 1000 as datetime, `Current A` as A FROM `TT`")
     or die ("error".mysql_error( ));
//     echo "all good";
while ($row = mysql_fetch_array($result)) {
$data[] = $row['datetime'];
$datab[] = $row['A'];
}
echo '?(' . "\n" . '['. "\n";
$count = count($data);
for ($i=0; $i<$count; $i++)
{
echo '['. str_replace('"', "", json_encode($data[$i], JSON_HEX_APOS)) . ',' . str_replace('"', "", json_encode($datab[$i], JSON$
}
//echo '('. json_encode(join($data, ',')) . ')';
echo ']);';
?>

But it doesn't work: when I refresh my page I don't see chart

Upvotes: 0

Views: 58

Answers (2)

J.Did
J.Did

Reputation: 1

oooo sory missing code

$count = count($data);
for ($i=0; $i<$count; $i++)
{
echo '['. str_replace('"', "", json_encode($data[$i], JSON_HEX_APOS)) . ',' . str_replace('"', "", json_encode($datab[$i], JSON_HEX_APOS)) .']' . ',' . "\n";
}
//echo '('. json_encode(join($data, ',')) . ')';
echo ']);';
?>

In console 0 error.

Upvotes: 0

mferly
mferly

Reputation: 1656

for ($i=0; $i<$count; $i++)
{
    echo '['.
        str_replace('"', "", json_encode($data[$i], JSON_HEX_APOS)) . ',' .
        str_replace('"', "", json_encode($datab[$i], JSON$ <----- What is this? Also missing 2 closing parenthesis ))
}

At the end of your echo you have JSON$ which is what, exactly? Not to mention you're missing a closing parenthesis in that final str_replace() and json_encode() which includes the JSON$.

In summary, it appears that you have some syntax errors that need to be resolved.

Upvotes: 1

Related Questions