Advertisement
mjasonm

Untitled

Apr 9th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1.  
  2. <?php include "libchart/classes/libchart.php";
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <title>volby</title>
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. <!-- Bootstrap -->
  10. <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
  11. </head>
  12. <body>
  13. <h1>volby</h1>
  14.  
  15. </br>
  16. <button id="add">add</button>
  17.  
  18. <script>
  19. var btn = document.getElementById('add');
  20. btn.addEventListener('click', function() {
  21.  
  22. document.location.href = 'add.php';
  23. });
  24. </script>
  25. <button id="delete">delete</button>
  26.  
  27. <script>
  28. var btn = document.getElementById('delete');
  29. btn.addEventListener('click', function() {
  30.  
  31. document.location.href = 'delete.php';
  32. });
  33. </script>
  34. <button id="update">update</button>
  35.  
  36. <script>
  37. var btn = document.getElementById('update');
  38. btn.addEventListener('click', function() {
  39.  
  40. document.location.href = 'update.php';
  41. });
  42. </script>
  43. <?php
  44.  
  45.  
  46. if(!$_ENV["VCAP_SERVICES"]){ //local dev
  47. $mysql_server_name = "127.0.0.1:3306";
  48. $mysql_username = "root";
  49. $mysql_password = "";
  50. $mysql_database = "test";
  51. } else { //running in Bluemix
  52. $vcap_services = json_decode($_ENV["VCAP_SERVICES" ]);
  53. if($vcap_services->{'mysql-5.5'}){ //if "mysql" db service is bound to this application
  54. $db = $vcap_services->{'mysql-5.5'}[0]->credentials;
  55. }
  56. else if($vcap_services->{'cleardb'}){ //if cleardb mysql db service is bound to this application
  57. $db = $vcap_services->{'cleardb'}[0]->credentials;
  58. }
  59. else {
  60. echo "Error: No suitable MySQL database bound to the application. <br>";
  61. die();
  62. }
  63. $mysql_database = $db->name;
  64. $mysql_port=$db->port;
  65. $mysql_server_name =$db->hostname . ':' . $db->port;
  66. $mysql_username = $db->username;
  67. $mysql_password = $db->password;
  68. }
  69. //echo "Debug: " . $mysql_server_name . " " . $mysql_username . " " . $mysql_password . "\n";
  70. $mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database);
  71.  
  72. if ($mysqli->connect_errno) {
  73. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  74. die();
  75. }
  76. $mysqli_result=mysqli_query($mysqli,"select id,strany,hlasy,hlasy2 from volby")or die(mysqli_error()); ;
  77. $hlasy;
  78. echo "<table border='1'>";
  79. echo "<tr> <th>id</th> <th>strany</th> <th>hlasy</th><th>hlasy 2. kolo</th> </tr>";
  80. // keeps getting the next row until there are no more to get
  81. $a=0;$b=0;$i=0;$hlasy;$hlasy2;$points;$points2;
  82. while($gear = mysqli_fetch_array( $mysqli_result )) {
  83.  
  84. // Print out the contents of each row into a table
  85. echo "<tr><td>";
  86. echo $gear['id'];
  87. echo "</td><td>";
  88. echo $gear['strany'];
  89. echo "</td><td>";
  90. echo $gear['hlasy'];
  91. echo "</td><td>";
  92. echo $gear['hlasy2'];
  93. echo "</td></tr>";
  94.  
  95. if($gear['hlasy']>=5){
  96. $a=1;
  97. $hlasy[$i]= $gear['strany'];
  98. $points[$i]=new Point( $gear['strany'],$gear['hlasy']);
  99. }
  100. if($gear['hlasy2']>=5){
  101. $hlasy2[$i]= $gear['strany'];
  102. $points2[$i]=new Point( $gear['strany'],$gear['hlasy2']);
  103. $b=1;
  104. }
  105. $i++;
  106.  
  107. }
  108. echo "</table>";
  109. mysqli_close($mysqli);
  110. echo "1.kolo:";
  111. foreach ($hlasy as $hlas):
  112. echo $hlas.",";
  113.  
  114. endforeach;
  115. echo "<br>";
  116. echo "2.kolo:";
  117. foreach ($hlasy2 as $hlas):
  118. echo $hlas.",";
  119.  
  120. endforeach;
  121. echo "<br>";
  122. $chart = new PieChart();
  123. if ($a==0){$points[0]=new Point( 0,0);}
  124. $dataSet = new XYDataSet();
  125. foreach ($points as $point):
  126. $dataSet->addPoint($point);
  127. endforeach;
  128. $chart->setDataSet($dataSet);
  129.  
  130. $chart->setTitle("postupujuci do parlamentu");
  131. $chart->render("demo3.png");
  132. if ($b==0){$points2[0]=new Point( 0,0);}
  133. $dataSet = new XYDataSet();
  134. foreach ($points2 as $point):
  135. $dataSet->addPoint($point);
  136. endforeach;
  137. $chart->setDataSet($dataSet);
  138.  
  139. $chart->setTitle("postupujuci do parlamentu 2.kolo");
  140. $chart->render("demo2kolo.png");
  141.  
  142.  
  143. ?>
  144. <div>
  145. <img alt="Pie chart" src="demo3.png" style="border: 1px solid gray;"/>
  146. <img alt="Pie chart" src="demo2kolo.png" style="border: 1px solid gray;"/>
  147. </div>
  148. </body>
  149. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement