php - Using database data in my javascript function -


I am working on a project where I want to create a visual chart with some data stored in my data database. / P>

Below you can see your phpcode to fetch data from the database. I

  $ query = "Select 'to' TBDDI '"; $ Result = mysql_query ($ query) or die ("SQL Error 1:". Mysql_error ()); ($ Line = mysql_fetch_array ($ result, MYSQL_ASSOC)) {$ command [] = array ('data' = & gt; $ row ['di_datum'], 'geowel' => $ line ['devival'] ); } Echo json_encode ($ command); ? & Gt;  

Now my javascript code for creating this chart is

  $ (function () {var bar_data = {data: [["January", 10 ], "[" "May", 17], ["June", 9]], color: "# 3c8dbc"}, ["February", 8], ["March", 4], ["April", 13] ; $ .plot ("# bar-chart", [bar_data], {grid: {borderWidth: 1, borderColor: "# f3f3f3", ticker: "# f3f3f3"}, series: {bars: {show: true, barve : 0.5, align: "center"}}, xxis: {modes: "categories", tick: length: 0}}) / * end bar chart * /};)  

So what i basically want, my javascript to my data from mysql Pt is to be implemented in the function. Therefore, months January, February, need to replace data from line ['di_datum'] and data should be replaced with data line [ 'Di_gevoel']

If you make an AJAX request and then map the results , You can use it to get your $ Plot plugin:

  $ (function () {$ .xx ({url: 'path / per / data', datatype: 'jason', method: 'gET'}) .done Function (data) for {var plottdata = []; (var i = 0; i & lt; data lamps; i ++) plotData.push ([data [i] .datum, parseInt (data [i]. Geowel;); var bar_data = {data: plotData, color: "# 3c8dbc"} $. Plot ("#bar-chart", [bar_data], {grid: {borderline: 1, border color: "# F3 F3F3 ", Ticker:" #F3F3F3 "}, Seri Es: {time: {show: true, barwidth: 0.5, align:" center "}}, xxis: {modes:" categories ", Tic: lun Dry: 0}}); / * and bar chart * /});});  

When your AJAX request is successful, it enters into the done method and you have access to the callback parameter, your feedback from the data variable, the plot data , Is just started as an empty array and fills the array for the loop.

The data returned from your AJAX request should be in the same name / price pair as the data in your example.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -