I need to display the values of an SQL table in a D3 map for each US state. Below is code excerpts from my file.php
:
-
Here is the SQL query:
$sql = "SELECT COUNT(State) FROM `mytable`"; $sql_result= mysqli_query($cnx,$sql) or die('Could not execute' . mysqli_error()) ;
-
Here is how I pass the result into an array
<? while($myvar=mysqli_fetch_array($sql_result)) { **need to add both php and javascript below..** } <?php $js_array = json_encode($myvar['0']);?>
-
Here is where I need to pass the data:
.forEach(function(d){ var kpi01=<?php echo "var nbcustomers = ". $js_array . "; ";?>, // No of customers in that state kpi02= ..... sampleData[d]={kpi01, kpi02}; });
Can anyone help me with suggestions to properly insert the JavaScript code after the while
loop within the .forEach
?