Hello.
Well im trying to create like a Vote system for a friend of mine.
It is supposed to order all things from Highest votes (Rank 1) To the lowest votes.
This will result in the Highest amount of votes being at the top of the table, my code doesn't do that.
Here is the website so fare:
http://toplist.ulmb.com/index.php?start=0
I have added Pagination so thats why there is a 1 down the bottom. Also might be the problem.
This is in the order of the Values i added into the Database (This is what it looks like inside the Database), But i wan't the Highest one "TestServerName' with "3424" to be at the top (EVERY FIELD ADDED SO FARE IS AN EXAMPLE)
But as you can see, its not.
Here is my code:
<?php
$dbhost = "mysql"; //Database Host
$dbuser = "####"; //Database User
$dbpass = "####"; //Database Password
$dbname = "####"; //Database Name
//connect
$db = mysql_pconnect($dbhost,$dbuser,$dbpass);
mysql_select_db("$dbname",$db);
//max displayed per page
$per_page = 20;
//get start variable
$start = $_GET['start'];
//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM data ORDER BY votes"));
//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 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))
{
// get data
$sname = $row['sname'];
$svotes = $row['votes'];
$details = $row['details'];
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>Rank</center>";
}
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++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='index.php?start=$next'>Next</a>";
?>
Any help?
EDIT:
Here is the votes field:
votes - text - latin1_swedish_ci - No