Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. +---------+------+----------------+-------+------+
  2. | user_id | name | email | score | tied |
  3. +---------+------+----------------+-------+------+
  4. | 1 | SB | sb@gmail.com | 1 | 0 |
  5. +---------+------+----------------+-------+------+
  6. | 2 | AS | as@web.de | 2 | 0 |
  7. +---------+------+----------------+-------+------+
  8. | 3 | BR | br@yahoo.com | 5 | 1 |
  9. +---------+------+----------------+-------+------+
  10. | 4 | PJ | pj@gmail.com | 5 | 1 |
  11. +---------+------+----------------+-------+------+
  12.  
  13. +------+-------------+-------+------+
  14. | rank | participant | score | tied |
  15. +------+-------------+-------+------+
  16. | 1 | BR | 5 | Yes |
  17. +------+-------------+-------+------+
  18. | 2 | PJ | 5 | Yes |
  19. +------+-------------+-------+------+
  20. | 3 | AS | 2 | No |
  21. +------+-------------+-------+------+
  22. | 4 | SB | 1 | No |
  23. +------+-------------+-------+------+
  24.  
  25. <table class="table table-hover" id="test">
  26. <thead>
  27. <tr>
  28. <th>Rank</th>
  29. <th>Participant</th>
  30. <th>Score</th>
  31. <th>Tied</th>
  32. </tr>
  33. </thead>
  34.  
  35. <tbody>
  36. <?php
  37. require("./php/createTable.php");
  38. ?>
  39. </tbody>
  40. </table>
  41.  
  42. <?php
  43. // Connection
  44. $conn = new mysqli('localhost', 'root', '', 'ax');
  45. if ($conn->connect_error) {
  46. die("Connection failed: " . $conn->connect_error);
  47. }
  48.  
  49. // SQL Query
  50. $sql = "SELECT * FROM names ORDER BY score DESC";
  51. $result = $conn->query("$sql");
  52.  
  53. // Initalizing of variables
  54. $count = 1;
  55. $previous = '';
  56.  
  57. while($row = mysqli_fetch_array($result)) {
  58. $current = $row['score'];
  59. $index = $result['user_id']
  60.  
  61. if ($current == $previous) {
  62. $update = "UPDATE names SET tied=0 WHERE user_id=$index";
  63. $conn->query($update);
  64. }
  65. $previous = $current;
  66. ?>
  67.  
  68. <tr>
  69. <td>
  70. <?php
  71. echo $count;
  72. $count++;
  73. ?>
  74. </td>
  75. <td><?php echo $row['name'];?></td>
  76. <td><?php echo $row['score'];?></td>
  77. <td>
  78. <?php
  79. if ($row['tied'] == 0) {
  80. echo 'No';
  81. } else{
  82. echo 'Yes';
  83. }
  84. ?>
  85.  
  86. </td>
  87. </tr>
  88.  
  89. <?php
  90. }
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement