provision Posted July 9, 2008 Share Posted July 9, 2008 Hi, This code displays the right amount of results but does not show the next or prev links.... I have no idea why.. Code: /* Set current, prev and next page */ $page = (!isset($_GET['page']))? 1 : $_GET['page']; $prev = ($page - 1); $next = ($page + 1); /* Max results per page */ $max_results = 10; /* Calculate the offset */ $from = (($page * $max_results) - $max_results); /* Query the db for total results. You need to edit the sql to fit your needs */ $result = mysql_query("select * from movies"); $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $max_results); $pagination = ''; /* Create a PREV link if there is one */ if($page > 1) { $pagination .= "<a href='index.php?page=".$prev."'>Previous</a> "; } /* Loop through the total pages */ for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i) { $pagination .= $i; } else { $pagination .= '<a href="index.php?page='.$i.'">$i</a>'; } } /* Print NEXT link if there is one */ if($page < $total_pages) { $pagination .= '<a href="index.php?page='.$next.'">Next</a>'; } /* Now we have our pagination links in a variable($pagination) ready to print to the page. I pu it in a variable because you may want to show them at the top and bottom of the page */ /* Below is how you query the db for ONLY the results for the current page */ $result=mysql_query("select * from movies LIMIT $from, $max_results "); print "<table id='movies'>"; print"<th>Title</th> <th>Director</th> <th>Genre</th> "; while($row = mysql_fetch_array($result)) { $title = $row['movie_name']; $director = $row['movie_director']; $genre = $row['genre']; print"<tr> <td>$title</td> <td>$director</td> <td>$genre</td> </tr>"; }; print"</table>"; Thanks Link to comment https://forums.phpfreaks.com/topic/113915-problem-with-pagenation/ Share on other sites More sharing options...
the shig Posted July 9, 2008 Share Posted July 9, 2008 howdy, try adding... <?php echo $pagination; ?> somewhere Link to comment https://forums.phpfreaks.com/topic/113915-problem-with-pagenation/#findComment-585372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.