Jump to content
Old threads will finally start getting archived ×

Aeolus

Members
  • Posts

    36
  • Joined

  • Last visited

    Never

Everything posted by Aeolus

  1. Whoops sorry So where I'm stuck is (I put it in the code) when I add the random numbers in before I execute the array for ranking, it assigns the same random number set to all of the users. If I put it in inside the array, it messes up the score - since the final score is calculated based on several natural scores added with the random numbers. Does that make any more sense? There isn't necessarily a bug in the script, I'm not getting any errors or anything, but it's just not doing what I want it to :/
  2. 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"); ?>
  3. No I just need to get all the players and their scores into the array without inserting them one by one... ie getting them from the table of players entered into the contest.. Thanks for all your help!
  4. Works perfectly now Same thing you had, but I changed $sql = "insert into events (rank, score, player) VALUES ($i, $value, $key)"; to $sql = "insert into events (rank, score, player) VALUES ('$i', '$value', '$key')";
  5. That's working great for displaying on a page, can't get it to insert into a database yet but give me a minute to fidget with it
  6. I think a simple select where phrase would help you out, where column=DC http://www.w3schools.com/php/php_mysql_where.asp
  7. The scores will be entered at the same time, that's what I'm trying to do anyway. And the scores will only be partially randomized, I'll be actually adding a randomized number to a previously existing score (so the random number is kind of an offset of what they already have). So.. [not in real coding here, obv]... get from table $previousscore for each player {for each player $previousscore + $randomscore = $finalscore} >> here is where I might use the temp table, to insert $finalscore for each player, and then get $finalscore from the temp table to do the ranking rank players by $finalscore insert into table $playername, $finalscore, rank
  8. I'll play with this, give me a few mins >> can you give me a snippet of your mysql table so I can insert that and save myself some time? Edit: Actually, do me a favor, try echoing all your values before you insert them into the table. If they don't echo, they aren't defined, and the problem is your form and not your mysql insert...
  9. I'll take a look at the links you posted, thanks! To answer your questions... Players will have a score randomized then their rank will be applied based off the score they received. So the player with the highest score would be ranked 1st, then 2nd, etc. etc. I need to insert the rank and the score they got into a "result" table. I wouldn't mind using a temporary table in there for the score, and I would drop that table at the end of the script. Does that make any more sense?
  10. I'm getting the same look - using FF
  11. So what I'm wanting to do is generate a randomized (well, it will be partially randomized anyway, but that's another story) number (score) for each player, and then rank players according to that score. I want to store the rank for each player, number of players entered, and the scores for each player into a table. This would be for like a weekly contest basically. I know I can use the php random # command to create my score, but I don't know how to rank the outputs. I know little to nothing about arrays, but I'm pretty sure that's where I need to begin. I'm sure I can read all I want about arrays - but how would I do what I'm trying to with an array? Any ideas? If I just get pointed in the right direction I would appreciate it greatly.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.