Uncaught SyntaxError: Unexpected token '<'

Coolguy69

Hi (and sorry as I am new to using this site), I am getting the error:

Uncaught SyntaxError: Unexpected token '<'

in the php code below:

while ($vrstica = mysqli_fetch_array($rezultat)) {
    echo  '<link rel="shortcut icon" href="#" />
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

    let podatki = [];
    podatki = <?php echo json_encode($vrstica); ?>; 

      google.charts.load("current", {"packages":["corechart"]});
      google.charts.setOnLoadCallback(drawChart);


        function drawChart(cas, hitrost) {

            let pomTabela = [["Datum", "Hitrost [m/s]"]];
            for(let i=0; i<podatki.length; i+=2){ 
                pomTabela.push([podatki[i],podatki[i+1]]);}

       var data = google.visualization.arrayToDataTable(pomTabela);


        var options = {
          title: "Povprecna hitrost vetra - zadnjih 7 dni",
          legend: { position: "bottom" }
        };

        var chart = new google.visualization.LineChart(document.getElementById("curve_chart"));

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

Now it seems a part of that code, bellow echo does not wish to be displayed here but its only some script brackets. Also the error is connected with the line (which is now also not fully displayed...): podatki = ;

Any help would be appreciated.

Martin Zeitler

This line would be echoed literally, resulting in a syntax error:

podatki = <?php echo json_encode($vrstica); ?>;

Try something alike this:

podatki = '.json_encode($vrstica).';

The first one ' ends the literal string, then comes the PHP execution result and the second one ' continues with the literal string (the opening and closing ' just happen to be in other lines).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related