Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +---------+------+----------------+-------+------+
- | user_id | name | email | score | tied |
- +---------+------+----------------+-------+------+
- | 1 | SB | sb@gmail.com | 1 | 0 |
- +---------+------+----------------+-------+------+
- | 2 | AS | as@web.de | 2 | 0 |
- +---------+------+----------------+-------+------+
- | 3 | BR | br@yahoo.com | 5 | 1 |
- +---------+------+----------------+-------+------+
- | 4 | PJ | pj@gmail.com | 5 | 1 |
- +---------+------+----------------+-------+------+
- +------+-------------+-------+------+
- | rank | participant | score | tied |
- +------+-------------+-------+------+
- | 1 | BR | 5 | Yes |
- +------+-------------+-------+------+
- | 2 | PJ | 5 | Yes |
- +------+-------------+-------+------+
- | 3 | AS | 2 | No |
- +------+-------------+-------+------+
- | 4 | SB | 1 | No |
- +------+-------------+-------+------+
- <table class="table table-hover" id="test">
- <thead>
- <tr>
- <th>Rank</th>
- <th>Participant</th>
- <th>Score</th>
- <th>Tied</th>
- </tr>
- </thead>
- <tbody>
- <?php
- require("./php/createTable.php");
- ?>
- </tbody>
- </table>
- <?php
- // Connection
- $conn = new mysqli('localhost', 'root', '', 'ax');
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // SQL Query
- $sql = "SELECT * FROM names ORDER BY score DESC";
- $result = $conn->query("$sql");
- // Initalizing of variables
- $count = 1;
- $previous = '';
- while($row = mysqli_fetch_array($result)) {
- $current = $row['score'];
- $index = $result['user_id']
- if ($current == $previous) {
- $update = "UPDATE names SET tied=0 WHERE user_id=$index";
- $conn->query($update);
- }
- $previous = $current;
- ?>
- <tr>
- <td>
- <?php
- echo $count;
- $count++;
- ?>
- </td>
- <td><?php echo $row['name'];?></td>
- <td><?php echo $row['score'];?></td>
- <td>
- <?php
- if ($row['tied'] == 0) {
- echo 'No';
- } else{
- echo 'Yes';
- }
- ?>
- </td>
- </tr>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement