pocobueno1388 Posted July 2, 2007 Share Posted July 2, 2007 I am having a bit of trouble getting my pagination to work correctly as there are some obstacles I have to work around in this specific script. I have the script recognizing how many results there are, and it correctly displays the amount of pages there should be for the amount of data, but when I try to go to any other page than the first, it loses the rest of the rows and doesn't display anything. Here is my code, I have narrowed it down as much as possible and deleted things you don't need to see so it is easier for you to look through. <?php if (isset($_POST['step3'])) { //put post data in variables $level = $_POST['level']; $show_levels = isset($_POST['show_levels']) ? $_POST['show_levels'] : "no_all"; $sort = isset($_POST['sort_by']) ? $_POST['sort_by'] : "fee DESC"; $show_type = $_POST['show_type']; //START PAGINATION if (!isset($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; } $max_results = 2; $from = (($page * $max_results) - $max_results); //start building query $query = "SELECT showID, name, fee, prize, level, run_date FROM shows WHERE type='$show_type'"; if ($show_levels == "all") { $query .= " AND level >= '$level'"; } else if ($show_level == "no_all") { $query .= " AND level = '$level'"; } $total_results = mysql_num_rows(mysql_query($query)); //<----Get number of results for pagination $query .= " ORDER BY $sort LIMIT $from, $max_results"; $result = mysql_query($query)or die(mysql_error()); //Start displaying info if (mysql_num_rows($result) > 0) { //show page numbers echo '<table width="70%" align="center"><td align="right">'; // Figure out the total number of pages. $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks echo "Page "; // Build Previous Link if ($page > 1) { $prev = ($page - 1); echo '<a href="shows.php?page='.$prev.'"><< Prev</a> '; } for ($i = 1; $i <= $total_pages; $i++) { if (($page) == $i) { echo "<b>[$i]</b> "; } else { echo '<a href="shows.php?page='.$i.'">['.$i.']</a> '; } } // Build Next Link if ($page < $total_pages) { $next = ($page + 1); echo '<a href="shows.php?page='.$next.'">Next>></a>'; } echo '</td></table>'; echo '<table class="dark" width="70%" align="center" cellpadding=8>'; while ($row = mysql_fetch_assoc($result)) { //This is just where I display the data from the DB } echo '</table>'; } else { echo "<center><i>No shows found.</i></center>"; } include 'footer.php'; exit; } ?> The only thing I can think of is it is losing it's POST information when you try to go to a different page, if thats possible. Also, you can see that my query is being setup in a slightly different way than just writing the whole thing out. So I wasn't sure where exactly to put this line: $total_results = mysql_num_rows(mysql_query($query)); Any help would be greatly appreciated with this =] Thank in advance. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 2, 2007 Share Posted July 2, 2007 ???The only thing I can think of is it is losing it's POST information when you try to go to a different page, if thats possible. ??? post entry will be lost because u use link in the navigation for pagination? so maybe thats why it terminate the execution of the script >>if (isset($_POST['step3'])) { try to figure it out Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 2, 2007 Author Share Posted July 2, 2007 Yeah, that is exactly what I was thinking was happening. Hmmm, any ideas on how to figure fix it? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 2, 2007 Share Posted July 2, 2007 you may use the session or the get to replace the post when the link is click but i suggest the get is better Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 2, 2007 Author Share Posted July 2, 2007 I don't really want to use sessions, I think there could be a better way. Even if I did use the get method, I would still have post data...so that wouldn't work. Maybe if I used define() on each varaible? Do you think it would hold the value? Quote Link to comment Share on other sites More sharing options...
MemphiS Posted July 2, 2007 Share Posted July 2, 2007 $_GET['']; would be your best bet.. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 2, 2007 Share Posted July 2, 2007 no define wont work get is the alternative because you only have few data to pass use this any way i know you know this $getvalu=(isset(yourpost here))?your post valu here :your get here; ?h=$getvalu Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 2, 2007 Author Share Posted July 2, 2007 Okay, I will just use GET to do it. Thanks guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.