• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] How does one make a top5?
#6
(2021-02-26, 05:22 AM)Kwarde Wrote: If you're using MySQL you can very easily select a top 5 based on certain data. For example, let's say we have this users table:\

Code:
+---+----------+------+-------+------

| id | name? ? ? | kills | deaths | score |

+---+----------+------+-------+------

|? 1 | Kwarde? ? |? ? 16 |? ? 25 |? ? 4 |

|? 2 | Playa? ? |? ? 2 |? ? 19 |? ? 1 |

|? 3 | Z3fRaN? ? |? ? 28 |? ? ? 1 |? 100 |

|? 4 | Narf3z? ? |? ? 1 |? ? 28 |? ? 0 |

|? 5 | MathPi? ? |? ? 99 |? ? ? 0 |? ? 50 |

|? 6 | Slayer? ? |? ? 66 |? ? 13 |? ? 25 |

|? 7 | JimmyPage |? ? 0 |? ? ? 2 |? ? 0 |

+---+----------+------+-------+------

Using this query:

Code:
SELECT name, kills FROM users ORDER BY kills DESC LIMIT 5;

This would select columns "name" and "kills" from the table "users" and order by kills, descending (DESC -- ASC would order ascending, and thus beginning with the lowest values). LIMIT 5 says: Limit to 5 results. The query itself should be pretty clear.

This would give this output:

Code:
+-------+------

| name? | kills |

+-------+------

| MathPi |? ? 99 |

| Slayer |? ? 66 |

| Z3fRaN |? ? 28 |

| Kwarde |? ? 16 |

| Playa? |? ? 2 |

+-------+------



Going through all user files is really unnecessary. This would need only 5 rows as the checking who has more kills would still be checked on the server live. There is no need to go through all user files.
  Reply


Messages In This Thread
How does one make a top5? - by Z3fRaN - 2021-02-26, 01:37 AM
RE: How does one make a top5? - by Virsenas - 2021-02-26, 02:18 AM
RE: How does one make a top5? - by Z3fRaN - 2021-02-26, 02:22 AM
RE: How does one make a top5? - by Virsenas - 2021-02-26, 04:24 AM
RE: How does one make a top5? - by Kwarde - 2021-02-26, 05:22 AM
RE: How does one make a top5? - by Virsenas - 2021-02-26, 11:54 AM
RE: How does one make a top5? - by Kwarde - 2021-02-27, 02:26 PM
RE: How does one make a top5? - by Virsenas - 2021-02-27, 08:43 PM
RE: How does one make a top5? - by arber - 2021-02-27, 11:30 PM
RE: How does one make a top5? - by Radical - 2021-02-27, 11:45 PM
RE: How does one make a top5? - by Z3fRaN - 2021-02-27, 11:55 PM

Forum Jump: