Ltj_bukem Posted November 13, 2007 Share Posted November 13, 2007 Hi, I am working on a simple pagination script, similar to the one on this sites tutorial section. I have a search form which displays the results on one page, if there are over 17 results a 2nd page is created, 34 results a third page & so on. The links between the pages work fine, the problem I have is that no matter what page I am on only the first pages results are displayed. I think it may be a problem with the actual links that create the new pages. Here's the code ?php $search= $_POST['search']; if (isset($_POST['go'])) { mysql_connect("***", "****", "*****") or die("Error connecting to MySQL: ".mysql_error()); mysql_select_db("******") or die("Error selecting database: ".mysql_error()); //$search = strtoupper($search); $search = strip_tags($search); $search= trim ($search); $query = "SELECT * FROM download1 WHERE dance LIKE '%$search%' OR name LIKE '%$search%'"; $result = mysql_query ($query); $total = mysql_num_rows($result); if ($search == "") { echo "<p>You forgot to enter a search term."; } if($total > 0) { echo "Searching for $search produced $total results"; echo "<br></br>"; } while (list($id, $name, $temp, $dance) = mysql_fetch_array($result)) { //while(list($id, $name, $temp, $dance) = mysql_fetch_array($result)) { // echo "<a href=\"$temp\">$name</a></br>"; echo "<br><a href=\"download3.php?id=$id\">$name</a></br>"; $searchvar = 1; } } echo "</ul>"; if ((!$search == "") && ($searchvar != 1)) {echo "<p>No matches found, please refine your search.";} } ?> Heres the page for the next & prev links if ( $pageNum> 1) { $page = $pageNum- 1; $prev = " <a href=\"$self?page=$page\">[Prev]</font></a> "; $first = " <a href=\"$self?page=1\">[First Page]</font></a> "; } else { $prev = '<font size="2" face="verdana">[Prev]</font>'; $first = '<font size="2" face="verdana">[First Page]</font>'; } if ( $page < $total_pages ) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = '<font size="2" face="verdana"> [Next] </font>'; // we're on the last page, don't enable 'next' link $last = '<font size="2" face="verdana"> [Last Page] </font>'; // nor 'last page' link } if ($pageNum == $total_pages) { $next = '<font size="2" face="verdana"> [Lext] </font>'; $last = '<font size="2" face="verdana"> [Last Page] </font>'; } echo $first.$prev."<font size='2' face='verdana'> Showing page </font><strong><font color='blue'>$pageNum</font></strong><font size='2' face='verdana'> of </font><strong><font color='blue'>$total_pages</font></strong><font size='2' face='verdana'> pages </font></strong></font>" . $next . $last; ?> [/Code] Any help would be cool, I'm almost there. Quote Link to comment Share on other sites More sharing options...
jscix Posted November 13, 2007 Share Posted November 13, 2007 Maybe not the best code, but it works and maybe it will give you an idea of what you need to do. # Get Paging data $getpgid = ($_GET['page']); if (!isset($getpgid)) { $getpgid = "1"; } if (!is_numeric($getpgid)) { $getpgid = "1"; } $clean2 = $getpgid . "0"; $clean1 = ($clean2 - 10); $getlistn = mysql_query("SELECT * FROM `events` "); if (!$getlistn) { die ("Unable to list events"); } # Print Page listings $cntx = mysql_num_rows($getlistn); // count the rows $divb = ceil(intval($cntx)/10)*10; // round total results to a number divisible by 10 $howmany = ceil($divb / 10); //number of times 10 goes into total rows Print "[ Pages: "; for ($ix = 1; $ix <= $howmany; $ix++) { if ($ix != $howmany) { echo "<a href=www.example.com&page=$ix>$ix</a> - "; } else { echo "<a href=www.example.com&page=$ix>$ix</a>"; } } print " ]"; $getlist = mysql_query("SELECT * FROM `events` LIMIT $clean1 , $clean2"); if (!$getlist) { die ("Unable to list projects"); } 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.