Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // DATABASE CONNECTION
- // define login credentials for the database
- // these must match the settings on your database
- $username = "root";
- $password = "";
- $host = "localhost";
- $database = "ao16_dummy_database";
- $table = "users";
- // connect to MySQL server
- // the function mysqli_connect(...) returns a link to the database which we store in the variable $link
- $link = mysqli_connect($host, $username, $password) or die("Connection to database server failed!");
- // NB: using die() is not the most elegant way to handle errors because it causes the site to only return
- // the error message, no styling and so on. A more elegant way would be to ensure the site keeps running
- // whenever possible and else print out errors in a more appealing page design ;)
- // select the database to work with
- mysqli_select_db($link, $database);
- // truncate tabel
- $sql_truncate = "TRUNCATE TABLE averages_final;";
- mysqli_query($link, $sql_truncate);
- $k = 0;
- $l = 12;
- $q = "";
- $submissions = [];
- $max_submissions = 0;
- while ($k < $l){ //for every group
- $q = "SELECT `ID` FROM `users` WHERE `group_id` = $k";
- $results = mysqli_query($link, $q);
- $max_submissions = 0;
- while ($data = mysqli_fetch_array($results)) {
- echo $data['ID'] . "<br>";
- $q = "SELECT COUNT(`ID`) AS ammount_submissions FROM `submissions` WHERE `userID` = {$data['ID']}";
- $results2 = mysqli_query($link, $q);
- $ubmissions = mysqli_fetch_array($results2)['ammount_submissions'];
- $max_submissions = max($max_submissions, $ubmissions);
- //var_dump($results2);
- }
- while ( <= 10) {
- # code...
- }
- $k++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement