Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php include "libchart/classes/libchart.php";
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>volby</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <!-- Bootstrap -->
- <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
- </head>
- <body>
- <h1>volby</h1>
- </br>
- <button id="add">add</button>
- <script>
- var btn = document.getElementById('add');
- btn.addEventListener('click', function() {
- document.location.href = 'add.php';
- });
- </script>
- <button id="delete">delete</button>
- <script>
- var btn = document.getElementById('delete');
- btn.addEventListener('click', function() {
- document.location.href = 'delete.php';
- });
- </script>
- <button id="update">update</button>
- <script>
- var btn = document.getElementById('update');
- btn.addEventListener('click', function() {
- document.location.href = 'update.php';
- });
- </script>
- <?php
- if(!$_ENV["VCAP_SERVICES"]){ //local dev
- $mysql_server_name = "127.0.0.1:3306";
- $mysql_username = "root";
- $mysql_password = "";
- $mysql_database = "test";
- } else { //running in Bluemix
- $vcap_services = json_decode($_ENV["VCAP_SERVICES" ]);
- if($vcap_services->{'mysql-5.5'}){ //if "mysql" db service is bound to this application
- $db = $vcap_services->{'mysql-5.5'}[0]->credentials;
- }
- else if($vcap_services->{'cleardb'}){ //if cleardb mysql db service is bound to this application
- $db = $vcap_services->{'cleardb'}[0]->credentials;
- }
- else {
- echo "Error: No suitable MySQL database bound to the application. <br>";
- die();
- }
- $mysql_database = $db->name;
- $mysql_port=$db->port;
- $mysql_server_name =$db->hostname . ':' . $db->port;
- $mysql_username = $db->username;
- $mysql_password = $db->password;
- }
- //echo "Debug: " . $mysql_server_name . " " . $mysql_username . " " . $mysql_password . "\n";
- $mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database);
- if ($mysqli->connect_errno) {
- echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
- die();
- }
- $mysqli_result=mysqli_query($mysqli,"select id,strany,hlasy,hlasy2 from volby")or die(mysqli_error()); ;
- $hlasy;
- echo "<table border='1'>";
- echo "<tr> <th>id</th> <th>strany</th> <th>hlasy</th><th>hlasy 2. kolo</th> </tr>";
- // keeps getting the next row until there are no more to get
- $a=0;$b=0;$i=0;$hlasy;$hlasy2;$points;$points2;
- while($gear = mysqli_fetch_array( $mysqli_result )) {
- // Print out the contents of each row into a table
- echo "<tr><td>";
- echo $gear['id'];
- echo "</td><td>";
- echo $gear['strany'];
- echo "</td><td>";
- echo $gear['hlasy'];
- echo "</td><td>";
- echo $gear['hlasy2'];
- echo "</td></tr>";
- if($gear['hlasy']>=5){
- $a=1;
- $hlasy[$i]= $gear['strany'];
- $points[$i]=new Point( $gear['strany'],$gear['hlasy']);
- }
- if($gear['hlasy2']>=5){
- $hlasy2[$i]= $gear['strany'];
- $points2[$i]=new Point( $gear['strany'],$gear['hlasy2']);
- $b=1;
- }
- $i++;
- }
- echo "</table>";
- mysqli_close($mysqli);
- echo "1.kolo:";
- foreach ($hlasy as $hlas):
- echo $hlas.",";
- endforeach;
- echo "<br>";
- echo "2.kolo:";
- foreach ($hlasy2 as $hlas):
- echo $hlas.",";
- endforeach;
- echo "<br>";
- $chart = new PieChart();
- if ($a==0){$points[0]=new Point( 0,0);}
- $dataSet = new XYDataSet();
- foreach ($points as $point):
- $dataSet->addPoint($point);
- endforeach;
- $chart->setDataSet($dataSet);
- $chart->setTitle("postupujuci do parlamentu");
- $chart->render("demo3.png");
- if ($b==0){$points2[0]=new Point( 0,0);}
- $dataSet = new XYDataSet();
- foreach ($points2 as $point):
- $dataSet->addPoint($point);
- endforeach;
- $chart->setDataSet($dataSet);
- $chart->setTitle("postupujuci do parlamentu 2.kolo");
- $chart->render("demo2kolo.png");
- ?>
- <div>
- <img alt="Pie chart" src="demo3.png" style="border: 1px solid gray;"/>
- <img alt="Pie chart" src="demo2kolo.png" style="border: 1px solid gray;"/>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement