I am new to web development. I just started programming in php. I want to create a dynamic page associated with a MySQL database (from the server) and display the result in a graph (there may be a spread, a histogram) in real time. So far I have managed to get data from my database and display a graph. However, I could not do this in real time.
I searched around. What I found is to use AJAX to create real-time graphs. Ok, I did a few lessons and was able to run the examples. My task is to build a schedule.
If this helps, this is exactly what I want to do http://jsxgraph.uni-bayreuth.de/wiki/index.php/Real-time_graphing
I tried to run this code but could not.
Can someone give me a simple way to start? I will clarify if my question is not clear enough. Thank you in advance!
@Tim, this is what I tried to do.
My php
<?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } else //echo "Database Connected!"; mysql_select_db("DB", $con); $sql=mysql_query("SELECT Def_ID, Def_BH FROM BBB WHERE Ln_Def < 1200"); $Def_ID= array(); $Def_BH = array(); while($rs = mysql_fetch_array($sql)) { $Def_ID[] = $rs['Def_ID']; $Def_BH [] = $rs['Def_BH ']; } mysql_close($con); $json = array( 'Def_ID' => $Def_ID, 'Def_BH' => $Def_BH ); echo json_encode($json); ?>
Output signal
{"Df_ID":["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41"],"Df_BH":["1","1","1","5","5","2","1","1","1","1","2","1","1","1","1","1","1","1","1","1","1","1","2","1","1","2","1","3","10","1","2","1","1","1","2","2","2","1","1","1","1","1"]}
Then my script follows
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Flot Example: Real-time updates</title> <link href="../examples.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript" src="../../jquery.js"></script> <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script> <script language = "javascript" type="text/javascript" src="Include/excanvas.js"></script> </head> <body> <div id="placeholder" style="width:600px;height:300px"></div> </body> <script type="text/javascript"> function doRequest(e) { var url = 'fakesensor.php'; </script> </html>
I would like to build Def_Id against Def_BH. Do you see what went wrong?