Jump to content

PHP/Mysql - Ranking Help (Counter)


Twist3d

Recommended Posts

Hello, well i have ran into a bit of a snag.

Im trying to create, like a Voting Toplist thing, and its going good so fare, until i hit this problem.

 

What i need to do is : http://toplist.ulmb.com/index.php?start=0

If you look on that page, you will see "Rank", and all of the values are 1.

this is what i don't want..

Here is what i do.

 

As you can see, there is also a Vote table, this contains the amount of times a person or people has voted.

Now, as you can see the Highest amount of votes is at the top, And has the rank 1. And second place has the second amount of votes, but it still says its rank 1. I want it to be rank 2, and for 3 rank 3 etc.

 

If you understand what im saying, difficult to explain.

But here is my code:

 

<?php

//Database connection

//max displayed per page
$per_page = 20;

//get start variable
$start = $_GET['start'];

//count records
$result=mysql_query("SELECT COUNT(*) FROM data") or die( mysql_error() ); 
$record_count = mysql_result($result , 0); 

//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal

if (!$start)
   $start = 0;
   
//display data
$get = mysql_query("SELECT * FROM data ORDER BY votes DESC LIMIT $start, $per_page"); 
echo "<center><table border='2' cellpadding='7' cellspacing='0' table width='600'></center>";
    echo "<center><tr> <th>Server Name</th> <th>Votes</th> <th>Details</th><th>Rank</th></tr></center>";
while ($row = mysql_fetch_assoc($get))
{

if (strlen($row['details']) > 10) // if len is more than 10 
{ // shorten it and add trailing dots. 
$details = substr($row['details'], 0, 15) . "..."; 
} 
else // len is less than 10, use original description. 
{ 
$details = $row['details']; 
} 

[b]$A=1;[/b] 
// get data
$sname = $row['sname'];
$svotes = $row['votes'];

echo "<tr><td>"; 
echo "<center>$sname</center>";
echo "</td><td>"; 
echo "<center>$svotes</center>";
echo "</td><td>"; 
echo "<center>$details</center>"; 
echo "</td><td>"; 
echo "<center>$A</center>";

[b]$A++;[/b]

}

echo "</table>";
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;

//show prev button
if (!($start<=0))

       echo "<a href='index.php?start=$prev'>Prev</a> ";

//show page numbers

//set variable for first page
$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
    echo " <a href='index.php?start=$x'>$i</a> ";
else
    echo " <a href='index.php?start=$x'><b>$i</b></a> ";
$i++;
}
$G++;
//show next button
if (!($start>=$record_count-$per_page))
       echo " <a href='index.php?start=$next'>Next</a>";
?>

 

As you can see, i have added an A counter in the bits in bold, but the A++; doesn't work, it doesn't plus it onto the next table.

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/184954-phpmysql-ranking-help-counter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.