Jump to content

Not working correctly!


rodhow

Recommended Posts

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>&nbsp ";
  }

// 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.

Link to comment
https://forums.phpfreaks.com/topic/252034-not-working-correctly/
Share on other sites

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

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());

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.