Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $mysqli =mysqli_connect('localhost', 'dunham_scrubgras', 'scrub123', 'dunham_scrubgrass');
  5. if (mysqli_connect_errno()) {
  6. echo "Failed to connect to MySQL: ".mysqli_connect_error();
  7. }
  8.  
  9.  
  10. $sql = mysqli_query($mysqli, 'SELECT Output, DA_Price, RT_PRICE, Margin FROM scrubgrass');
  11.  
  12. if (!$sql) {
  13. die("Error running $sql: " . mysql_error());
  14. }
  15.  
  16.  
  17.  
  18. $results = array();
  19. while($row = mysqli_fetch_assoc($sql))
  20. {
  21. $results[] = array(
  22. 'Output' => $row['Output'],
  23. 'DA_Price' => $row['DA_Price'],
  24. 'RT_PRICE' => $row['RT_PRICE'],
  25. 'Margin' => $row['Margin']
  26. );
  27. }
  28. $json = json_encode($results, JSON_PRETTY_PRINT);
  29. //echo $json;
  30.  
  31. ?>
  32.  
  33. <html>
  34. <head>
  35. <title>Graphs</title>
  36. <!-- Load jQuery -->
  37. <script language="javascript" type="text/javascript"
  38. src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
  39. </script>
  40. <!-- Load Google JSAPI -->
  41. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  42. <script type="text/javascript">
  43. google.load("visualization", "1", { packages: ["corechart"] });
  44. google.setOnLoadCallback(drawChart);
  45.  
  46. function drawChart() {
  47. var jsonData = $.ajax({
  48. url: "php/tracker.php",
  49. dataType: "json",
  50. async: false
  51. }).responseText;
  52.  
  53. var obj = window.JSON.stringify(jsonData);
  54. var data = google.visualization.arrayToDataTable(obj);
  55.  
  56. var options = {
  57. title: 'graph'
  58. };
  59.  
  60. var chart = new google.visualization.LineChart(
  61. document.getElementById('chart_div'));
  62. chart.draw(data, options);
  63. }
  64.  
  65. </script>
  66. </head>
  67. <body>
  68. <div id="chart_div" style="width: 900px; height: 500px;">
  69. </div>
  70. </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement