forumnz Posted January 31, 2008 Share Posted January 31, 2008 How do I figure out how many pages there will be? I have num_rows, but that just returns the amount or results on one page. Thanks, Sam. Link to comment https://forums.phpfreaks.com/topic/88783-pagination-problem/ Share on other sites More sharing options...
darkfreaks Posted January 31, 2008 Share Posted January 31, 2008 you need something like <?php $i=o; while ($variable =<$i) { //dostuff } else{ //echo stuff $i++;} ?> Link to comment https://forums.phpfreaks.com/topic/88783-pagination-problem/#findComment-454737 Share on other sites More sharing options...
uwannadonkey Posted January 31, 2008 Share Posted January 31, 2008 set the number of rows that you want on each page, and then figure it out: something like this: this is a basic one i use $page_num = $_GET['page']; if(empty($page_num)) { $page_num = 1; } $ppp = 20; //posts per page $min_ppp = ($ppp*$page_num)-$ppp; $query = mysql_query("SELECT * FROM users") or die(mysql_error()); $num_rows = mysql_num_rows($query); $query = mysql_query("SELECT * FROM users ORDER BY level desc LIMIT $min_ppp, $ppp") or die(mysql_error()); $rows = mysql_num_rows($query); $pages = ceil($num_rows/$ppp); while($row = mysql_fetch_array($query)) { $id= $row['ID']; $name = $row['display_name']; $level= $row['level']; $gold = $row['gold']; $alive = $row['hp']; if($alive >= 1) { $alive2 = YES; } else { $alive2 = NO; } $attack = Attack; $hp=$row['hp']; $hp1=$row['max_hp']; echo "<tr><td><font color=#ffffff>$id</font></td><td>"; echo" <td><font color=#FFFFFF>$level</font></td><td><font color=#FFFFFF>$gold</font></td><td><font color=#FFFFFF>$alive2</font></td><td><font color=#FFFFFF>$hp/$hp1</font></td><td><a href =donkeyattack.php?ID=$id><font color=#FFFFFF>$attack</font></a></td></tr>"; } echo ' </table>'; if($page_num == 1) { echo "Prev "; } else { $prev_page = $page_num-1; echo "<a href=\"{$PHP_SELF}?page={$prev_page}\">Prev</a>"; } for($i = 1; $i <= $pages; $i++) { if($i == 1) { echo " "; } if($i == $page_num) { echo $i; } else { echo "<a href=\"{$PHP_SELF}?page={$i}\">{$i}</a>"; } if($i != $pages) { echo ", "; } else { echo " "; } } if($page_num == $pages) { echo "Next"; } else { $next_page = $page_num+1; echo "<a href=\"{$PHP_SELF}?page={$next_page}\">Next</a><br><br><BR>"; } Link to comment https://forums.phpfreaks.com/topic/88783-pagination-problem/#findComment-454739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.