Re: [PHP-DB] PHP Results on multiple pages
[email protected] (Chris)
| Newsgroups | php.db |
|---|---|
| Message-ID | <[email protected]> |
> 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.
It takes roughly 20 secs to do a search? Perhaps that should also be
looked at.
Try to narrow down your problem.
> // begin to show results set
> echo " found $numrows results <p>";
> $count = 1 + $s;
Where does $s come from? What is it supposed to mean? (Name your
variables properly).
> // now you can display the results returned
> while ($row= mysql_fetch_array($result)) {
>
> $title = $row["sname"];
> $url = $row["url"];
> $message = $row["massage"];
> // <a href=\"$row['url']\">"$row['sname']</a><br />
> $row['massage']<br><hr>'\
>
> echo "$count.) ";
> 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 " <a href='{$_SERVER['PHP_SELF']}?s=$prevs&q=$var'> <<<
> Prev 10</a>  ";
> }
>
> // 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++;
> }
What is $s set to here when there's extra pages to display?
> // check to see if last page
> if (!((($s+$limit)/$limit)==$s) && $s!=1) {
That's just too complicated to read. The first part seems redundant
since you're calculating $s anyway, why re-do it?
// are there extra pages to display?
if ($s > 1) {
echo "show extra pages";
}
> // not last page so give NEXT link $PHP_SELF >>
> $news="$s+$limit";
>
> echo " <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.
>
>
--
Postgresql & php tutorials
http://www.designmagick.com/