Simple Ranking Script
Posted: Wed Apr 07, 2010 8:15 pm
I'm in the process of creating a ranking script for the users of my website, but am running in to problems. All I need is one that shows the first x amount of users, then has links at the bottom for x - x+50, etc, etc, only for the number of existing users. For example, if there are 263 users, I don't want it to have links for 300-350, only 1-50, 50-100, 100-150, 150-200, 200-250, 250-300.
My current code is going to have to be switched up a LOT I think, as right now, the way I see it, for each new page it will start the ranks back at 0 and go through x -- but here it goes.
My current code is going to have to be switched up a LOT I think, as right now, the way I see it, for each new page it will start the ranks back at 0 and go through x -- but here it goes.
Code: Select all
function doRanks() {
$rank = 0;
//$total = 0; Plan was to have total be the total number of users already shown
$query = mysql_query("SELECT * FROM `table` ORDER BY `number` DESC");
$num_sites = mysql_num_rows($query);
while($row = mysql_fetch_array($query)){
$rank++;
if($rank <= 20) {
echo "--User info--";
if ($rank == 12 && $rank != 3)
{
echo "<div class=\"box\">Advertisement #2!</div>";
}
if ($rank == 3)
{
echo "<div class=\"box\">Advertisement!</div>";
}
echo "<div class=\"hr\"></div>";
}
}
if ($num_sites % 20) {
$next = 0;
$next = $next;
$query = mysql_query("SELECT * FROM `table` ORDER BY `id` DESC");
$number = mysql_num_rows($query);
$repeat = ceil($number/$this->max); //So I can set the max number shown?
while ($repeat > 0) {
switch ($repeat) {
case 1:
echo "[<a href='?rank=2'>50-100</a>]";
break;
case 2:
echo "[<a href='?rank=3'>100-150</a>]";
break;
//Would go on, but for testing purposed I only need these two
default:
break;
}
$repeat--;
}
}
}