Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- //==========================================
- //DB config
- //==========================================
- $servername = "localhost";
- $username = "root";
- $password = "KRe9bUn9U8eGKnWB";
- $dbname = "missu2016";
- //==========================================
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT cv.candidate_id,c.name,c.country,COUNT(cv.candidate_id) as number_votes FROM count_votes as cv INNER JOIN candidate as c ON c.id = cv.candidate_id GROUP BY candidate_id ORDER BY COUNT(candidate_id) DESC";
- $votes = $conn->query($sql);
- $count_votes = array();
- if ($votes->num_rows > 0) {
- // output data of each row
- while($row = $votes->fetch_assoc()) {
- echo"
- <tr>
- <td>".$row["candidate_id"]."</td>
- <td>".$row["candidate_id"]."</td>
- <td>".$row["candidate_id"]."</td>
- <td>".$row["candidate_id"]."</td>
- <td>".$row["candidate_id"]."</td>
- </tr>
- ";
- $count_votes[] = array("id"=>$row['candidate_id'],"name"=>$row['name'],"country"=>$row['country'],"votes"=>$row['number_votes']);
- }
- }
- $count_votes = array("lists"=>$count_votes);
- echo json_encode($count_votes);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement