Created
September 22, 2020 10:28
-
-
Save geektutor/91d7b2c44ff6185850c6bc0be521f0bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include './config/connect.php'; | |
//i don't know what i am writing tho, i hope it works sha | |
$first ="UPDATE `user` SET `score` = '0' WHERE `score` > 0"; | |
$reset = mysqli_query($conn, $first); | |
$sql = "SELECT email FROM user"; | |
$result = mysqli_query($conn, $sql); | |
$count = mysqli_num_rows($result); | |
if ($count > 0) { | |
while($row = mysqli_fetch_assoc($result)) { | |
$particular_user = $row['email']; | |
$up = total_score($particular_user); | |
update_total($particular_user, $up); | |
} | |
} | |
function total_score($email){ | |
global $conn; | |
$queryURL = "SELECT `points` FROM submissions WHERE `user` = '$email' "; | |
$resultURL = mysqli_query($conn, $queryURL); | |
$countURL = mysqli_num_rows($resultURL); | |
$total = 0; | |
if ($countURL > 0) { | |
while($row = mysqli_fetch_assoc($resultURL)) { | |
$total += $row['points']; | |
} | |
return $total; | |
}else{ | |
return $total; | |
} | |
} | |
function update_total($email, $total){ | |
global $conn; | |
$query = "UPDATE user SET score = $total WHERE `email` = '$email' "; | |
$result = mysqli_query($conn, $query); | |
if($conn->query($query)){ | |
return 1; | |
}else{ | |
return 0; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment