rodhow Posted November 29, 2011 Share Posted November 29, 2011 Hello, I am pasting code below that isn't working corrrectly. One problem is the pagination. When I get more than 10 records, it will show the next 10 link but when I click on it, it just takes me back to an empty page with NO results. How do I fix this? Also where do I insert the block of code for a table to structure my results. As of now, the returned results are all over the page! Thanks! This is the code: <?php // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row["1st_field"]; echo "$count.) $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> MOD EDIT: . . . BBCode tags added. Quote Link to comment https://forums.phpfreaks.com/topic/252034-not-working-correctly/ Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2011 Share Posted November 29, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/252034-not-working-correctly/#findComment-1292166 Share on other sites More sharing options...
btellez Posted November 29, 2011 Share Posted November 29, 2011 Have you tested to see if the query to the database returns any records after you click the link? I am guessing it may be an issue with your query. Can you post your query? Quote Link to comment https://forums.phpfreaks.com/topic/252034-not-working-correctly/#findComment-1292173 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2011 Share Posted November 29, 2011 Pagination involves two queries, the first one to get the total number of matching rows (so that you can correctly calculate and limit the number of pages) and the second query to get the actual block of rows that corresponds to the page number that was requested by clicking on the link. See this tutorial - http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/252034-not-working-correctly/#findComment-1292178 Share on other sites More sharing options...
rodhow Posted November 29, 2011 Author Share Posted November 29, 2011 yes the script does return the proper number of records. I get ten records on the first page displaying '1 to 10 of x number of records' at the bottom with tne next 10 link appearing but when I click it, it doesn't show the rest of records plus displays a blank page with just a search box. This is the query used $query .= "limit $s,$limit"; $result = mysql_query($query) or die($query."|".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/252034-not-working-correctly/#findComment-1292181 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2011 Share Posted November 29, 2011 Best guess is that your code is not putting the correct value in to the $s variable. Quote Link to comment https://forums.phpfreaks.com/topic/252034-not-working-correctly/#findComment-1292295 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.