Jump to content

bartibus

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bartibus's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, The problem is though that the scores are variable; the user A, etc. was just an example. I have tried to change the code so that it will retrieve the users and scores from the database, but the resulting list gives every user the same rank. This is my code: <? $query = "SELECT username, name, totaal FROM punten ORDER BY totaal DESC, name ASC"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc ($result)) { $username= $row['username']; $name= $row['name']; $totaal= $row['totaal']; $scores = array($name => $totaal); $rank = 1; $prev = 0; $count = 0; foreach ($scores as $name => $totaal) { if ($totaal==$prev) { ++$count; } else { $rank = ++$count; } echo "$rank $name $totaal<br />"; $prev = $totaal; } } ?> Do you know what is wrong with my code?
  2. Hi, Does anyone know how I can make a rank list from a series of numbers? I have a competition in which participants can gather points; in a mysql database table there's a row for each participant (users) and a column in which the point totals are saved (totals). When I use 'ORDER BY' to sort the users according to their totals, the rank is consecutive, even when two or more users have the same amount of points. Is it possible to make a script that sorts the users according to their totals and assigns a rank number, that remains the same if two or more users have the same total (and skips the relevant rank numbers)? Below is an example of what I would like to have: 1 User A 200 2 User B 150 3 User C 125 3 User D 125 3 User E 125 6 User F 100 I hope that someone can help me with this, Thanks in advance, Bart
  3. Now that I have the totals in a separate column, I would like to show a competition ranking. If I select the relevant columns, sort them on 'totals' in descending order, and show this in a table, the list shows the following: Rank Name Totals 1 User A 200 2 User B 150 3 User C 150 4 User D 100 Is it possible to assign ranks like you would do in a competition (A:1, B:2, C:2, D:4)? Below is the code I use right now: [code]<? function showRanglijst(){    global $database;                     $query = "SELECT username, name, totaal FROM punten ORDER BY totaal DESC LIMIT 0, 10";                     $result = mysql_query($query) or die(mysql_error());    $num_rows = mysql_numrows($result);    if(!$result || ($num_rows < 0)){       echo "Error displaying info";       return;    }    if($num_rows == 0){       echo "Database table empty";       return;    }    echo "<table align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"380\">\n";    echo "<tr><td><b>Nr.</b></td><td><b>Naam</b></td><td><b>Punten</b></td></tr>\n";    for($i=0; $i<$num_rows; $i++){       $username  = mysql_result($result,$i,"username");     $name   = mysql_result($result,$i,"name");     $totaal   = mysql_result($result,$i,"totaal");     $nummer = $i+1;       echo "<tr><td>$nummer</td><td><a href=\"userinfo.php?user=$username\" title=\"$username\">$name</a></td><td>$totaal</td></tr>\n";    }    echo "</table><br>\n"; } ?>[/code]
  4. I tried Barand's code and that seems to do it. That simple! I had been playing around with looping codes but that's not necessary it seems. Anyway, thanks a lot! Bart
  5. Hi all, I have difficulties coming up with the right script for the following: I have a mysql database table in which I store a (large) amount of data (numbers) for different users. Each row has a column with a unique username, and several columns in which the numbers are stored. I want to add those numbers for each username and save the total in another column (preferably in the same table), and would like to do this automatically in stead of doing the same over and over again for each user. Does anybody know how to get there? Thanks in advance! Bart
×
×
  • 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.