Twist3d Posted December 20, 2009 Share Posted December 20, 2009 Hello again. Well im still building my Toplist thing and ive hit a bit of a snag. My Toplist has Pagination on it, as you are all aware this just displays a maximum amount of values and makes a new page. But this is not good. I also have a Ranking system (1 - 100 etc). How this votes, is which ever Thing has the most amount of Votes, it will goto the top of the list. And will be Rank #1. I just have a Counter going down for the ranking. But here is my problem: At every new page (I have made 4 values in the Database, and set it to 1 value per page, so there is 4 pages) on each new page, it starts the counter from the beginning. at #1. So here is an example: Page 1: #Rank 1 #Rank 2 #Rank 3 Page2: #Rank 1 #Rank 2 #Rank 3 This is page, Page 2 should look like this: #Rank 4 #Rank 5 #Rank 6 That is the best explanation of what im trying to do. Here is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <a href=index.php><center><img src="images/Banner.jpg" width="580" height="142" /></center></a> <?php //Connecting to the Database: //max displayed per page $per_page = 1; //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"); while ($row = mysql_fetch_assoc($get)) { if (strlen($row['sdetail']) > 10) // if len is more than 10 { // shorten it and add trailing dots. $sdetail = substr($row['sdetail'], 0, 30) . "..."; } else // len is less than 10, use original description. { $sdetail = $row['sdetail']; } // get data $sname = $row['sname']; $svotes = $row['votes']; $id = $row['ID']; $G++; ?> <body> <div align="center"> <img src="/images/navbar.png" width="720" height="25" /> </div> <table width="1328" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutDefaultTable--> <tr> <td width="428" height="3"></td> <td width="88"></td> <td width="47"></td> <td width="431"></td> <td width="88"></td> <td width="246"></td> </tr> <tr> <td height="56"> </td> <td valign="top"><div align="center"><?php echo $G; ?></div></td> <td> </td> <td valign="top"><?php echo "<a href=viewserver.php?id=$id>$sname</a>"; ?><br /> <?php echo $sdetail; ?></td> <td valign="top"><div align="center"><?php echo $svotes; ?><br /> <font size="1"> <?php echo "<a href=voteserver.php?id=$id>[Vote for this server]</a>"; ?> </font> </div></td> <td> </td> </tr> </table> <?php } echo "<center>"; //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>"; echo "</center>"; ?> </body> </html> As you can see i have: //max displayed per page $per_page = 1; On 1 so there is 1 value per page, this will make it 4 pages as i said. But this does work if this is on 20, It will count down to 4, But it will start again on 1 the next page. Any help? Quote Link to comment https://forums.phpfreaks.com/topic/185754-ranking-on-pagination/ Share on other sites More sharing options...
sasa Posted December 20, 2009 Share Posted December 20, 2009 setup $G=$start; before loop Quote Link to comment https://forums.phpfreaks.com/topic/185754-ranking-on-pagination/#findComment-980836 Share on other sites More sharing options...
Twist3d Posted December 20, 2009 Author Share Posted December 20, 2009 Ok so: //display data $get = mysql_query("SELECT * FROM data ORDER BY votes DESC LIMIT $start, $per_page"); setup $G=$start; while ($row = mysql_fetch_assoc($get)) { if (strlen($row['sdetail']) > 10) // if len is more than 10 { // shorten it and add trailing dots. $sdetail = substr($row['sdetail'], 0, 30) . "..."; } else // len is less than 10, use original description. { $sdetail = $row['sdetail']; } I added your code. And its gives me an error. Parse error: syntax error, unexpected T_VARIABLE in /hosted/subs/ulmb.com/t/o/toplist/public_html/index.php on line 37 Quote Link to comment https://forums.phpfreaks.com/topic/185754-ranking-on-pagination/#findComment-980838 Share on other sites More sharing options...
Twist3d Posted December 20, 2009 Author Share Posted December 20, 2009 NVM sorry, i just relized i copied your entire code. Man im a fool. Thanks heeps! Quote Link to comment https://forums.phpfreaks.com/topic/185754-ranking-on-pagination/#findComment-980846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.