PHP Results on multiple pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello guys,
I am having a search script which supose to take results out of my mysql
database and display on a page 10 results
if the results are more then 10 it should create another page
or pages with Next >> and Prev << link so anyone can move
forward and backward on those results page.

This script do everything fine counting total records
it display's 1 to 10 records on first page with numbers but
second location where i want it to display Showing results 1 to 10 it shows
17 to 26 second it displays a link to Next but not working.

// begin to show results set
echo " found  $numrows results <p>";
$count = 1 + $s;

// now you can display the results returned
 while ($row= mysql_fetch_array($result)) {

 $title = $row["sname"];
 $url = $row["url"];
 $message = $row["massage"];
//&nbsp;<a href=\"$row['url']\">"$row['sname']</a><br />
$row['massage']<br><hr>'\

 echo "$count.)&nbsp";
 echo "<b><a href=\"$url\" target=\"_blank\">$title</a></b>";
 echo "<br>";
 echo "$message<br><hr height=12 color=lightblue><br>";
 $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 "&nbsp;<a href='{$_SERVER['PHP_SELF']}?s=$prevs&q=$var'> <<<
 Prev 10</a>&nbsp&nbsp;";
 }

// calculate number of pages needing links
//  $s=intval($numrows/$limit);
 $s=ceil($numrows/$limit);


// $s now contains int of pages needed unless there is a remainder from
division

 if ($numrows%$limit) {
 // has remainder so add one page
 $s++;
 }

// check to see if last page
 if (!((($s+$limit)/$limit)==$s) && $s!=1) {

 // not last page so give NEXT link  $PHP_SELF &gt;&gt;
 $news="$s+$limit";

 echo "&nbsp;<a href='{$_SERVER['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>";
include ('footer.inc');
?>

I shall highly appreciate if anyone shall have a look at it
and let me know where i am wrong.

Thank you.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux