Grabbing SQL data using PHP then sending Array to Javascript -
I am trying to find out how to parse SQL data in a JavaScript file using PHP
I need to store the PHP array in Java because I have a graph that uses a javascript array to populate the data.
Now I have a button that refreshes my graph data, and when it is clicked it calls this JavaScript which is included in my main HTML file: < P> button.js
$ (function () {$ ('# refreshchurch'). (Function () {Var chart = $ ('# chart'). High Chart () ; Chart. Series [0] .Setetta (Dataera);});}); Java SAR "Datarae" needs to be pulled from the SQL database.
I have PHP scripts that pull data from the database.
Here is my PHP script:
query.php
& lt; Php included 'dbcon.php'; $ Query0 = "Select Count (*) from test WHERE ans = 0"; $ Query1 = "test number (*) test WHERE ans = 1"; $ Query2 = "Testing with Selection Count (*) where 2 ans = 2"; $ Query3 = "Test Count from (*) where answer = 3"; $ Query4 = "test number (*) test WHERE ans = 4"; $ Query5 = "test number (*) test WHERE ans = 5"; $ Query6 = "test count (*) test WHERE ans = 6"; $ Query7 = "Select Count (*) from Test WHERE ans = 7"; $ Query8 = "test number (*) test WHERE ans = 8"; $ Query9 = "Selection Number (*) from Test where ans = 9"; $ Result0 = $ mysqli-> Query ($ query0) or die ($ mysqli-> error .__ LINE__); $ Result1 = $ mysqli-> Query ($ query1) or die ($ mysqli-> error .__ LINE__); $ Result2 = $ mysqli- & gt; Query ($ query2) or die ($ mysqli-> error .__ LINE__); $ Result3 = $ mysqli-> Query ($ query3) or die ($ mysqli-> error .__LINE__); $ Result4 = $ mysqli- & gt; Query ($ query4) or die ($ mysqli-> error .__ LINE__); $ Result5 = $ mysqli- & gt; Query ($ query5) or die ($ mysqli-> error .__ LINE__); $ Result6 = $ mysqli-> Query ($ query6) or die ($ mysqli-> error .__LINE__); $ Result7 = $ mysqli- & gt; Query ($ query7) or die ($ mysqli-> error .__ LINE__); $ Result8 = $ mysqli-> Query ($ query8) or die ($ mysqli-> error .__ LINE__); $ Result9 = $ mysqli- & gt; Query ($ query9) or die ($ mysqli-> error .__ LINE__); $ Line 0 = $ result0- & gt; Fetch_row (); $ Line1 = $ result1- & gt; Fetch_row (); $ Line2 = $ result 2- & gt; Fetch_row (); $ Line3 = $ result3- & gt; Fetch_row (); $ Line 4 = $ result 4- & gt; Fetch_row (); $ Line 5 = $ result 5- & gt; Fetch_row (); $ Row6 = $ result 6 & gt; Fetch_row (); $ Line 7 = $ result-7-> Fetch_row (); $ Row8 = $ result8->; Fetch_row (); $ Row9 = $ result9- & gt; Fetch_row (); The echo "The number of people, who chose A:", $ line 1 [0]; Number of people chosen for "echo": ", $ line 2 [0]; The number of people in the choice of "resonant" & lt; br & gt; c, $ line 3 [0]; Resonant "& lt; br & gt; Number of people selected in D:", $ 4 [0]; Echo "Number of people who have e select:", $ 5 [0]; Resonant "& lt; br> the number of people that F: selected", $ row6 [0]; Echo "& lt; br & gt; Number of G: Choose Live: $ 7 [0]; Echo "& lt; br> The number of people with the election of H:", $ 8 [0]; Resonant "& lt; br & gt; I have selected the number of those people:", $ 9 [0]; Echo "& lt; br & gt; Number of people, who chose J:", $ line 0 [0]; $ Array = array ($ line 1 [0], $ line 2 [0], $ line 3 [0], $ line 4 [0], $ line 5 [0], $ line 6 [0], $ Row 7 [0], $ 8, [0], $ row9 [0], $ row0 [0]); Echo json_encode ($ array); ? & Gt; Now I know that I have to encode the PHP array using JSN so that it is formatted correctly and I have to use AJAX to call PHP a PHP script get data.
This is where I get stuck, I'm not sure how to get results and parse them into the Java array so that the graph can be updated with the result in the SQL database.
Any help would be appreciated!
Thank you, Christopher
If you call your php-code through AJAX Want to:
$ (function () {var chart = $ ('# chart'). Highcharts (); $ ('click (function () {$ .ajax ({ Type: "GET", url: "some.php", success: function (data) {chart.series [0] .setdata ($. ParseJSON (info));}});});}) Just set "some.php" in your php-file name.
Comments
Post a Comment