bluewaves Posted May 30, 2007 Share Posted May 30, 2007 I'm trying to use this as a template for pagination. I got it working for one product line, but then as I tried another and replaced the variables, the pagination failed to produce a viewable page to click to. It numbers all the pages and counts the records, it just doesn't create the page. Any clues??? ??? <?php // Number of records to show per page: $display_number = 3; // Connect to MySQL: include('../misc.inc'); $database = "voipvide_checks"; $cxn = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); mysql_select_db($database); // Determine how many records there are: if (isset($_GET['np'])) { $num_pages = (int) $_GET['np']; } else { // Find out how many records there are. $q = "SELECT COUNT(*) FROM trendy"; // Get the number. $r = mysql_query($q); list($num_records) = mysql_fetch_array($r, MYSQL_NUM); mysql_free_result($r); // Calculate the number of pages: if ($num_records > $display_number) { $num_pages = ceil ($num_records/$display_number); } else { $num_pages = 1; } } // Determine where in the database to start returning results: if (isset($_GET['s'])) { $start = (int) $_GET['s']; } else { $start = 0; } // Define the query: $q = "SELECT * FROM trendy ORDER BY Price ASC LIMIT $start, $display_number"; // Run the query: $r = mysql_query ($q); // Display all of the records: $max_columns = 3; while ($row = @mysql_fetch_array ($r, MYSQL_ASSOC)) { echo " <table width='600'> <tr> <td colspan='2' bgcolor='#FFFFFF'><B><font face='Arial' size='2'><a href='{$row['Link']}'>{$row['Name']}</B></a> - \${$row['Price']}</font> </td> </tr> <tr> <td width='400' valign='left'><P><a href='{$row['Link']}'> <font face='Arial' size='2'><img border='0' src='{$row['Thumbnail']}'></a><P><font face='Arial' size='2'> </font></td> </tr> </table>\n"; } // Clean up: mysql_close($cxn); // Make the links to other pages, if necessary: if ($num_pages > 1) { echo '<hr width="50%" align="center" />'; // Determine what page the script is on: $current_page = ($start/$display_number) + 1; // If it's not the first page, make a Previous button: if ($current_page != 1) { echo '<center><a href="paginationtrendy.php?s=' . ($start - $display_number) . '&np=' . $num_pages . '"> Previous</a>'; } // Make all the numbered pages: for ($i = 1; $i <= $num_pages; $i++) { // Don't link the current page: if ($i != $current_page) { echo '<a href="paginationtrendy?s=' . (($display_number * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button: if ($current_page != $num_pages) { echo '<a href="paginationtrendy?s=' . ($start + $display_number) . '&np=' . $num_pages . '"> Next</a> '; } } ?> Link to comment https://forums.phpfreaks.com/topic/53640-solved-pagination-script-works-one-time-and-then-doesnt/ Share on other sites More sharing options...
bluewaves Posted May 30, 2007 Author Share Posted May 30, 2007 Whoops. I figured this out myself. Every time I replaced the page name, I erased the .php. Now that I put it back, it works...Oh well...I hope that someone learns from my stupid mistake. Link to comment https://forums.phpfreaks.com/topic/53640-solved-pagination-script-works-one-time-and-then-doesnt/#findComment-265202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.