So here's what I'm trying to do.
1) Get all users from a table, where they have natural scores recorded.
2) Add random number on top of each natural score
3) Combine the natural scores into one final score
4) Order and rate (starting with 1) users based off the final score
5) Insert into an event table the rating, score, and username
Here's what I have so far...
<?php require_once("inc/config.php");
include("inc/header.php");
$connection = mysql_connect($dbHost,$dbUser,$dbPass);
if (!$connection) { die("Database connection failed: " . mysql_error());}
$db_select = mysql_select_db($dbName,$connection);
if (!$db_select) { die("Database selection failed: " . mysql_error()); }
// requesting
$result = @mysql_query("SELECT * FROM users");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
/* here is where I think I need to add the random score, but then it adds the same score to each user,
and I want each user to have their own randomized number */
//I have plugged 4 in for now, but would like the next three lines to read + $random instead of + 4
$score_d = $row ['nat_d'] + 4;
$score_j = $row ['nat_j'] + 4;
$score_c = $row ['nat_c'] + 4;
$score_final = $score_d + $score_j + $score_c;
$assocArray[$row['name']] = $score_final;
arsort($assocArray, SORT_NUMERIC);
$i = 1;
};
foreach ($assocArray as $key => $value) {
// request
$result = @mysql_query("SELECT * FROM users WHERE name='$key'");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
$score_d = $row ['nat_d'] + 4;
$score_j = $row ['nat_j'] + 4;
$score_c = $row ['nat_c'] + 4;
echo $i . ' <b>' . $row ['name'] . '</b> | ';
printf("%05.2f", $score_d); echo ' | ';
printf("%05.2f", $score_c); echo ' | ';
printf("%02.0f", $score_j); echo ' | ';
echo $value . ' |<br><br>';
/*$sql = "insert into event (rank, score, user) VALUES ('$i', '$value', '$key')";
$query = mysql_query($sql);
*/
$i++;
};
};
include("inc/footer.php"); ?>