Advertisement
Guest User

Untitled

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