contra10 Posted July 23, 2009 Share Posted July 23, 2009 I'm trying to do this pagination script but everytime i click on "page 2" or "last" i get the same data in page one, basically nothing happens except for the url that changes from something like this http://localhost/outdoor/next/ to http://localhost/outdoor/next/index.php?pagenum=2 <?php // Connects to your Database mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("deals") or die(mysql_error()); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $querye = "SELECT * FROM `deal` WHERE `category` = 'Outdoor' and `time` = '704'"; $result = mysql_query($querye) or die(mysql_error()); $rows= mysql_num_rows($result); //This is the number of results displayed per page $page_rows = 2; $es = ($rows/$page_rows); //This tells us the page number of our last page $last = ceil($es); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM `deal` WHERE category = 'Outdoor' and time = '704' $max") or die(mysql_error()); //This is where you display your query results while ($postede = mysql_fetch_assoc($data_p)) { $title = "{$postede['title']}"; $imagename = "{$postede['imagename']}"; $time = "{$postede['time']}"; $titled = stripslashes($title); $url = "{$postede['url']}"; $on= "on"; $off= "off"; echo "<tr>"; echo"<td width='10%' height='200'><a href='$url' target='_blank'><img src='http://localhost/includes/704/$imagename.jpg'></a></td>"; echo "</tr>"; echo "<tr><td></td></tr>"; } echo"<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?p=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?p=$previous'>$Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?p=$next'>$next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?p=$last'>Last ->></a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167136-solved-data-through-pages/ Share on other sites More sharing options...
waynew Posted July 23, 2009 Share Posted July 23, 2009 Hi could you try <?php // Connects to your Database mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("deals") or die(mysql_error()); $pagenum = 1; //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $querye = "SELECT * FROM `deal` WHERE `category` = 'Outdoor' and `time` = '704'"; $result = mysql_query($querye) or die(mysql_error()); $rows= mysql_num_rows($result); //This is the number of results displayed per page $page_rows = 2; $es = ($rows/$page_rows); //This tells us the page number of our last page $last = ceil($es); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM `deal` WHERE category = 'Outdoor' and time = '704' $max") or die(mysql_error()); //This is where you display your query results while ($postede = mysql_fetch_assoc($data_p)) { $title = "{$postede['title']}"; $imagename = "{$postede['imagename']}"; $time = "{$postede['time']}"; $titled = stripslashes($title); $url = "{$postede['url']}"; $on= "on"; $off= "off"; echo "<tr>"; echo"<td width='10%' height='200'><a href='$url' target='_blank'><img src='http://localhost/includes/704/$imagename.jpg'></a></td>"; echo "</tr>"; echo "<tr><td></td></tr>"; } echo"<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?p=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?p=$previous'>$Previous</a> "; } //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?p=$next'>$next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?p=$last'>Last ->></a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167136-solved-data-through-pages/#findComment-881258 Share on other sites More sharing options...
contra10 Posted July 23, 2009 Author Share Posted July 23, 2009 i still have the same problem Quote Link to comment https://forums.phpfreaks.com/topic/167136-solved-data-through-pages/#findComment-881261 Share on other sites More sharing options...
waynew Posted July 23, 2009 Share Posted July 23, 2009 Could you echo out $pagenum etc just before it goes to the select query? Quote Link to comment https://forums.phpfreaks.com/topic/167136-solved-data-through-pages/#findComment-881265 Share on other sites More sharing options...
contra10 Posted July 23, 2009 Author Share Posted July 23, 2009 This is what echoes out $pagenum = 1 $last = 3 $es = 3 Quote Link to comment https://forums.phpfreaks.com/topic/167136-solved-data-through-pages/#findComment-881269 Share on other sites More sharing options...
contra10 Posted July 23, 2009 Author Share Posted July 23, 2009 when i click pg 2. the results that are on the first page stays displayed Quote Link to comment https://forums.phpfreaks.com/topic/167136-solved-data-through-pages/#findComment-881302 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.