Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. // DATABASE CONNECTION
  3.  
  4.  
  5. // define login credentials for the database
  6. // these must match the settings on your database
  7. $username = "root";
  8. $password = "";
  9. $host = "localhost";
  10. $database = "ao16_dummy_database";
  11. $table = "users";
  12.  
  13.  
  14. // connect to MySQL server
  15. // the function mysqli_connect(...) returns a link to the database which we store in the variable $link
  16. $link = mysqli_connect($host, $username, $password) or die("Connection to database server failed!");
  17.  
  18.  
  19. // NB: using die() is not the most elegant way to handle errors because it causes the site to only return
  20. // the error message, no styling and so on. A more elegant way would be to ensure the site keeps running
  21. // whenever possible and else print out errors in a more appealing page design ;)
  22.  
  23.  
  24. // select the database to work with
  25. mysqli_select_db($link, $database);
  26.  
  27. // truncate tabel
  28. $sql_truncate = "TRUNCATE TABLE averages_final;";
  29. mysqli_query($link, $sql_truncate);
  30.  
  31. $k = 0;
  32. $l = 12;
  33. $q = "";
  34. $submissions = [];
  35. $max_submissions = 0;
  36.  
  37. while ($k < $l){ //for every group
  38. $q = "SELECT `ID` FROM `users` WHERE `group_id` = $k";
  39. $results = mysqli_query($link, $q);
  40.  
  41. $max_submissions = 0;
  42.  
  43. while ($data = mysqli_fetch_array($results)) {
  44. echo $data['ID'] . "<br>";
  45.  
  46. $q = "SELECT COUNT(`ID`) AS ammount_submissions FROM `submissions` WHERE `userID` = {$data['ID']}";
  47. $results2 = mysqli_query($link, $q);
  48. $ubmissions = mysqli_fetch_array($results2)['ammount_submissions'];
  49. $max_submissions = max($max_submissions, $ubmissions);
  50. //var_dump($results2);
  51. }
  52. while ( <= 10) {
  53. # code...
  54. }
  55.  
  56. $k++;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement