wintallo Posted November 13, 2006 Share Posted November 13, 2006 I got this script from a pagination tutorial on this site an it works great except one thing. I want to add a rank column to a highscore table. The problem is, when it's displayed, the first page's ranks are 1-10, but on the second page, when it should be numbered 11-20, it starts over again at one. How can I fix it so it keeps counting up as you go through the page. Here's the code[code]<table width="500" border="1" align="center" cellspacing="1" cellpadding="2"> <tr> <td colspan="4"><div align="center"><strong>Tetris Highscores</strong></div></td> </tr> <tr> <td width="37"><strong>Rank</strong></td> <td width="234"><strong>Name</strong></td> <td width="38"><strong>Score</strong></td> <td width="160"><strong>Date</strong></td> </tr><?phpinclude 'db.php';if(!isset($_GET['page'])){ $page = 1;} else { $page = $_GET['page'];}$max_results = 10;$from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM tetris ORDER BY score DESC LIMIT $from, $max_results");$rank = 1;while($row = mysql_fetch_array($sql)){ echo "<tr><td>"; echo $rank; echo "</td><td>"; echo $row['name']; echo "</td><td>"; echo $row['score']; echo "</td><td>"; echo $row['date']; echo "</td></tr>"; $rank = $rank + 1;}$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM tetris"),0);$total_pages = ceil($total_results / $max_results);echo "<center>Select a Page<br />";if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; }}if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";}echo "</center>";?></table>[/code]THanks for reading!Joelwintallo.com Link to comment https://forums.phpfreaks.com/topic/27054-solved-pagination-problem/ Share on other sites More sharing options...
Destruction Posted November 13, 2006 Share Posted November 13, 2006 Hmm, how about multiplying $rank by $page. So if it's the 5th rank of page 3 it'll show as rank 15.HTHDest Link to comment https://forums.phpfreaks.com/topic/27054-solved-pagination-problem/#findComment-123738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.