Lyss Posted February 23, 2007 Share Posted February 23, 2007 i'm using this php code in my search form, the page numbers are showing up, but when i click page two it doesn't load the next search results. can someone try and help figure out what's wrong! if it helps to know, the form searches files not a mysql database. this is the code: // Display Search Results if(is_array($found_arr)){ //Pagination $results_per_page = 20; $page = ($_GET['page'] ? $_GET['page'] : ''); $i = $page; $j = 0; //End Pagination foreach($found_arr as $news_id => $archive){ //Pagination if ($j < $page){ $j++; continue; } $i++; //End Pagination if($archive){$all_news = file("$cutepath/data/archives/$archive.news.arch");} else{ $all_news = file("$cutepath/data/news.txt"); } foreach($all_news as $single_line){ $item_arr = explode("|",$single_line); $local_id = $item_arr[0]; if($local_id == $news_id){ ////////// Showing Result echo"<br /><b><a href="$PHP_SELF?misc=search&subaction=showfull&id=$local_id&archive=$archive&cnshow=news&ucat=$item_arr[6]&start_from=&$user_query">$item_arr[2]</a></b> (". date("d F, Y", $item_arr[0]) .")"; ////////// End Showing Result } } //Pagination if ($i >= $results_per_page + $page){ break; } //Pagination } //Pagination if($_POST['story']){ $PHP_SELF = $PHP_SELF.'?dosearch=yes'.($_POST['do'] ? '&do='.$_POST['do'] : '').'&story='.$_POST['story']; } else{ $get = cute_query_string($QUERY_STRING, array("page")); $get = '?'.$get; $PHP_SELF = $PHP_SELF.$get; } $total_pages = @ceil(count($found_arr) / $results_per_page); $current_page = ($page/$results_per_page) + 1; $pages = ''; //Advanced pagination if ($total_pages > 10){ //Left block $pages_start = 1; $pages_max = $current_page >= 5 ? 3 : 5; for($j = $pages_start; $j <= $pages_max; $j++){ if($j == $current_page){ $pages .= '<b>'.$j.' </b>'; } else{ $pages .= '<a href="'.$PHP_SELF.'&page='.(($j - 1) * $results_per_page).'">'.$j.' </a>'; } } $pages .= '... '; //Middle block if($current_page > 4 && $current_page < ($total_pages - 3)){ $pages_start = $current_page - 1; $pages_max = $current_page + 1; for($j = $pages_start; $j <= $pages_max; $j++){ if($j == $current_page){ $pages .= '<b>'.$j.' </b>'; } else{ $pages .= '<a href="'.$PHP_SELF.'&page='.(($j - 1) * $results_per_page).'">'.$j.' </a>'; } } $pages .= '... '; } //Right block $pages_start = $current_page <= $total_pages - 4 ? $total_pages - 2 : $total_pages - 4; $pages_max = $total_pages; for($j = $pages_start; $j <= $pages_max; $j++){ if($j == $current_page){ $pages .= '<b>'.$j.' </b>'; } else{ $pages .= '<a href="'.$PHP_SELF.'&page='.(($j - 1) * $results_per_page).'">'.$j.' </a>'; } } } //Normal pagination else { for ($j = 1; $j <= $total_pages; $j++){ if ((($j - 1) * $results_per_page) != $page){ $pages .= '<a href="'.$PHP_SELF.'&page='.(($j - 1) * $results_per_page).'">'.$j.' </a>'; } else{ $pages .= '<b>'.$j.' </b>'; } } } echo '<br /><br />'.$pages; //End pagination }else{ echo"There are no news matching your search criteria"; } Link to comment https://forums.phpfreaks.com/topic/39771-pagination/ Share on other sites More sharing options...
monk.e.boy Posted February 23, 2007 Share Posted February 23, 2007 who wrote the code? It looks like you need to set $_GET['page'], like this: http://www.site.com/you_page.php?page=2 have you done this? monk.e.boy Link to comment https://forums.phpfreaks.com/topic/39771-pagination/#findComment-192133 Share on other sites More sharing options...
Ninjakreborn Posted February 23, 2007 Share Posted February 23, 2007 Here is an example of what I use. These are tested, I reuse and remodify the same initial script I created a long time ago, it always serves my purpose everytime with a little modification. <?php if ($_GET['rownumberprev']) { $rownumber = mysql_real_escape_string($_GET['rownumberprev']); }elseif ($_GET['rownumbernext']) { $rownumber = mysql_real_escape_string($_GET['rownumbernext']); }else { $rownumber = 0; } $limit = 20; $selectall = "SELECT * FROM safetyreport ORDER BY dateoccured DESC;"; $queryall = mysql_query($selectall); $total_rows = mysql_num_rows($queryall); $select = "SELECT * FROM safetyreport ORDER BY dateoccured DESC LIMIT $rownumber, $limit;"; $query = mysql_query($select); echo "<hr />"; echo "<br />"; echo "<table align=\"center\">"; while ($row = mysql_fetch_array($query)) { echo "<tr>"; echo "<td>"; $datefilledout = date("m/d/Y", $row['dateoccured']); echo $datefilledout; echo " - "; echo "</td>"; echo "<td>"; if ($row['confidential'] == "no") { echo stripslashes($row['name']) . " - "; }elseif ($row['confidential'] == "yes") { echo "Masked" . " - "; } echo "</td>"; echo "<td>"; echo "<a href=\"viewallsafetyinfo.php?id={$row[id]}\" title=\"View All Information\">View</a>"; echo " "; echo "<a href=\"editsafety.php?id={$row[id]}\" title=\"Edit Event\"> Edit</a>"; echo " "; echo "<a href=\"deletesafety.php?id={$row[id]}\" title=\"Delete\">Delete</a>"; echo "</td>"; echo "</tr>"; echo "<tr><td><hr /></td><td><hr /></td><td><hr /></td></tr>"; } echo "</table>"; if ($rownumber != 0) { $rownumberprev = $rownumber - $limit; echo "<a href=\"viewsafety.php?rownumberprev={$rownumberprev}\">Previous Page</a>"; echo "<br />"; } if ($rownumber <= ($total_rows - $limit)) { $rownumbernext = $rownumber + $limit; echo "<a href=\"viewsafety.php?rownumbernext={$rownumbernext}\">Next Page</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/39771-pagination/#findComment-192296 Share on other sites More sharing options...
Lyss Posted February 28, 2007 Author Share Posted February 28, 2007 who wrote the code? It looks like you need to set $_GET['page'], like this: http://www.site.com/you_page.php?page=2 have you done this? monk.e.boy I got the code from here --> http://democute.de.funpic.de/cute/example2.php?subaction=showfull&id=1166120966&archive=&start_from=&ucat=6 The link to page 2 looks like this: http://www.hp-ships.com/cutenews/search.php?&page=5 Link to comment https://forums.phpfreaks.com/topic/39771-pagination/#findComment-195717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.