eRott Posted March 11, 2007 Share Posted March 11, 2007 Okay, I have been trying to figure out how to get a working Pagnation set up on my website. However, every script, every tutorial I have looked at, has not worked; including both tutorials from this website. Could someone please help me out with this problem. It's just not working. Below is the code I currently am using. All that shows is "Select a Page". Thank you in advance. <?php // Open and Connect to Database Connection include 'db_config.php'; include 'db_open.php'; // If current page number, use it // if not, set one! if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Define the number of results per page $max_results = 10; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); // Perform MySQL query on only the current page number's results $sql = mysql_query("SELECT * FROM $table_name WHERE type='Action' LIMIT $from, $max_results"); echo "<table width='100%' border='0' cellspacing='0' cellpadding='5' align='left'>"; while($row = mysql_fetch_array($sql)){ // Build your formatted results here. echo "<tr>"; echo "<td>"; echo "<a href='games/{$row['srcname']}/{$row['src']}'><img src='games/thumbs/{$row['thumb']}' border='0' height='60' width='70'></a>"; echo "</td>"; echo "<td>"; echo "<b><font color='#000'>{$row['name']}</font></b><br>{$row['description']}"; echo "</td>"; echo "</tr>"; } echo "</table>"; // Figure out the total number of results in DB: $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM $table_name"),0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks echo "<center>Select a Page<br>"; // Build Previous Link 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> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"; } echo "</center>"; // Close Database Connection include 'db_close.php'; ?> Best Regards, eRott Link to comment https://forums.phpfreaks.com/topic/42171-pagination-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.