Question: Page-by-page navigation works, but when navigating through it, for example, on page 2, it writes:

Not found the requested URL / book / page was not found on this server.

include "set.php"; $num = 5; $page = $_GET['page']; $result = mysql_query("SELECT COUNT(*) FROM products"); $posts = mysql_result($result, 0); $total = intval(($posts - 1) / $num) + 1; $page = intval($page); if(empty($page) or $page < 0) $page = 1; if($page > $total) $page = $total; $start = $page * $num - $num; $result = mysql_query("SELECT * FROM products LIMIT $start, $num"); while ( $postrow[] = mysql_fetch_array($result)) echo "<table>"; for($i = 0; $i < $num; $i++) { echo "<tr> <td>".$postrow[$i]['title']."</td> <td>".$postrow[$i]['price']."</td></tr>"; } echo "</table>"; if ($page != 1) $pervpage = '<a href= ./page?page=1><<</a> <a href= ./page?page='. ($page - 1) .'><</a> '; if ($page != $total) $nextpage = ' <a href= ./page?page='. ($page + 1) .'>></a> <a href= ./page?page=' .$total. '>>></a>'; if($page - 2 > 0) $page2left = ' <a href= ./page?page='. ($page - 2) .'>'. ($page - 2) .'</a> | '; if($page - 1 > 0) $page1left = '<a href= ./page?page='. ($page - 1) .'>'. ($page - 1) .'</a> | '; if($page + 2 <= $total) $page2right = ' | <a href= ./page?page='. ($page + 2) .'>'. ($page + 2) .'</a>'; if($page + 1 <= $total) $page1right = ' | <a href= ./page?page='. ($page + 1) .'>'. ($page + 1) .'</a>'; echo $pervpage.$page2left.$page1left.'<b>'.$page.'</b>'.$page1right.$page2right.$nextpage; 
  • Your message is extremely similar to the 404th apache error. Just in case, give the .htaccess file code and tell me the address of the first page. - Mikhail Rebrov

1 answer 1

Initially hard to understand your letter. And the very conclusion of pagination recommended you re-register. That sketched quickly

 <? for ($i = 1; $i< $total; $i++) { if ($i == $page) { ?> <span class="page_active"><?=$i?></span> <? } else { echo "<a href='./page?=$i/'>$i</a>"; } } ?> 
  • I could not resist, if you write the answer, then at least somehow observe the formatting and any rules of writing code for example <? it is better to replace with <?php , while with for to replace, correct indents, whatever may be wrong. And expand if with else and remove echo . - Naumov