Twist3d Posted December 13, 2009 Share Posted December 13, 2009 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 More sharing options...
Twist3d Posted December 13, 2009 Author Share Posted December 13, 2009 Help anyone? I really need this. Link to comment https://forums.phpfreaks.com/topic/184954-phpmysql-ranking-help-counter/#findComment-976382 Share on other sites More sharing options...
anthylon Posted December 13, 2009 Share Posted December 13, 2009 Hello there, Check line 36 - you have: A=1; . Simple remove /or/ comment it and your counter should work! Is that what you wanted to achieve? :-\ Writing shorter question gives you more chance to get reply. Link to comment https://forums.phpfreaks.com/topic/184954-phpmysql-ranking-help-counter/#findComment-976394 Share on other sites More sharing options...
anthylon Posted December 13, 2009 Share Posted December 13, 2009 Okay I see on your link - you testing it. You commented line 36 and now just add A=1; before line 26 (while ($row = mysql_fetch_assoc($get))). It should work... Link to comment https://forums.phpfreaks.com/topic/184954-phpmysql-ranking-help-counter/#findComment-976396 Share on other sites More sharing options...
Twist3d Posted December 13, 2009 Author Share Posted December 13, 2009 Thanks! I thought that is what you needed But there is 1 small problem, it completely leaves out a row and doesn't give it a rank, then the 1 starts on the second row: Take a look: http://toplist.ulmb.com/index.php?start=0 Link to comment https://forums.phpfreaks.com/topic/184954-phpmysql-ranking-help-counter/#findComment-976397 Share on other sites More sharing options...
Twist3d Posted December 13, 2009 Author Share Posted December 13, 2009 Nvm, i got it working. thanks a ton mate. Link to comment https://forums.phpfreaks.com/topic/184954-phpmysql-ranking-help-counter/#findComment-976399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.