guitar idiot Posted November 24, 2007 Share Posted November 24, 2007 Hey I'm making just a small forum and heres the code I have so far(Yes I have all the MySql stuff I just didn't copy/paste it)<?phpwhile($row = mysql_fetch_array($result)) { echo '<div>'; echo '<a href="showthread.php?id=' . $row['id'] . '">'; echo $row['title'] . '</a>'; echo '<span class="time">' . $row['time'] . '</span>'; echo '<br />'; echo 'Created by ' . $row['username']; echo '<br />'; echo '</div>'; } ?>How can make go next page after 10 threads and on hte next page still pick up where it left off? Link to comment Share on other sites More sharing options...
mc_keny Posted November 24, 2007 Share Posted November 24, 2007 hmmm try this <?php //get in what page are you if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 5;//you can change how much row's show in page $to = ($page * $max_results) - $max_results; $form = $to - $max_result; $sql = mysql_query("SELECT * FROM `some_table` LIMIT $to, $max_results"); while($row=mysql_fet ch_array($sql)){ //printing your data } $page_sql = mysql_query("SELECT * FROM `some_table`"); $total_results = mysql_num_rows($pag e_sql);//how much rows are in table $total_pages = ceil($total_results / $max_results); //go back if it need if($page > 1){ $prev = ($page - 1); print '<a href="some.php?page= '.$prev.'">Back</a><br/>'; } //go to next page if that exist if($page < $total_pages){ $next = ($page + 1); print '<a href="some.php?page=' .$next.'">Next</a><br/>'; } ?> Link to comment Share on other sites More sharing options...
Matpatnik Posted November 24, 2007 Share Posted November 24, 2007 You can use those function: // starts the pagination functionfunction startpagination() { // defines a few globals needed for endpagination() global $cur_page, $max_results, $from; // If current page number, use it // if not, set one! if(empty($_GET['page'])){ $cur_page = 1; } else { $cur_page = $_GET['page']; } // Define the number of results per page $max_results = 9; // Figure out the limit for the query based on the current page number. $from = (($cur_page - 1) * $max_results);}// wraps up where startpagination() left off// $total is the total of picture overall function endpagination($max_results, $cur_page, $total) { global $pagination; // total of picture in the section divided by the $max_result $total_pages = ceil($total / $max_results); if ($cur_page > $total_pages ) { $cur_page = $total_pages; } $page_start = 1; $page_stop = $total_pages; // first and previous page if ($cur_page > 1) { $firstpage = " <a href=\"" . $_SESSION['php_self'] . "?section=gallery&cat=" . $_GET['cat'] ."&type=" . $_GET['type'] . "&page=1\">|<< First</a> "; $previouspage = " <a href=\"" . $_SESSION['php_self'] . "?section=gallery&cat=" . $_GET['cat'] ."&type=" . $_GET['type'] . "&page=" . ($cur_page - 1) . "\">< Previous</a> "; } else { $previouspage = ""; $firstpage = ""; } // next and last page if ($cur_page < $total_pages) { $nextpage = "<a href=\"" . $_SESSION['php_self'] . "?section=gallery&cat=" . $_GET['cat'] ."&type=" . $_GET['type'] . "&page=" . ($cur_page +1) . "\">Next ></a> "; $lastpage = "<a href=\"" . $_SESSION['php_self'] . "?section=gallery&cat=" . $_GET['cat'] ."&type=" . $_GET['type'] . "&page=" . $total_pages . "\">Last >>|</a>"; } else { $nextpage = ""; $lastpage = ""; } // middle pages for($i = 1; $i <= $total_pages; $i++) { // if $i is equal $cur_page don't link it if (($cur_page == $i) || ($cur_page == "")) { $show_page .= "[$i] "; } else { $show_page .= '<a href="' . $_SESSION['php_self'] . '?section=gallery&cat=' . $_GET['cat'] ."&type=" . $_GET['type'] . '&page=' . $i . '">' . $i . '</a> '; } } return '<div align="center">' . $firstpage . $previouspage . $show_page . $nextpage . $lastpage . '</div>';} You just have to secure the $_GET and your good to go. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.