Re: limiting rows and pages like google -- again

From: Date: Thu, 13 Sep 2001 12:45:22 +0000
Subject: Re: limiting rows and pages like google -- again
Groups: php.general 
Request: Send a blank email to php-general+get-67191@lists.php.net to get a copy of this message
> > Do you want to list all the pages of posts or just a link to the next 20 > > items? > > On the first page, 20 and links to the other items that when selected will > display the list based on the selection. > > One thing to remember is that the ids will not be in squence. Here's a function I wrote to do that. I can't promise that it isn't still buggy, but it's been working on my forum for a while now. /*************************************************************************/ /* print nextLinks * Prints a list of "next page" links for a list of items * spanning more than one page. * The links look something like this: * Page 1 | 2 | 3 * It cycles through the array of IDs supplied by the user * and prints one every "itemsPerPage" interval * param idArray - an array of all the id numbers of the thing that the menu relates to * param pageURL - the actual url for the pages that are linked * param itemsPerPage - the number of items per page * param currentID - the ID of the last item on the current page */ function printNextLinks($idArray, $pageURL, $itemsPerPage, $currentID, $direction) { // variables $postCount = count($idArray); $postPlace = 0; $iteration = 1; $threadLinks = ""; $lastID = $idArray[$postCount - 1]; $firstNextPage = $idArray[0]; // we only want the pages link if there is more than one page if ($postCount > $itemsPerPage && $firstNextPage != '') { while($postPlace <= $postCount && $firstNextPage != '') { $thisID = $idArray[$postPlace]; $nextPlace = $postPlace + $itemsPerPage; $lastCurrentPage = $idArray[$nextPlace - 1]; $firstNextPage = $idArray[$nextPlace]; if($lastCurrentPage == "") { $lastCurrentPage = $thisID; } // end if if(($currentID == $lastCurrentPage) && ($thisID != '') && $direction == "desc") { $threadLinks .= " $iteration |"; } else if (($currentID == $lastID) && ($firstNextPage == '') && $direction == "desc") { $threadLinks .= " $iteration |"; } else if (($currentID == $lastCurrentPage) && ($thisID != '')) { $threadLinks .= " $iteration |"; } else if (($currentID == $lastID) && ($firstNextPage == '')) { $threadLinks .= " $iteration |"; } else { $threadLinks .= " <A HREF=\"".$pageURL."ID=$thisID\">$iteration</A> |"; } // end else // move everything along $postPlace = $nextPlace; $iteration ++; } // end while // remove the last line from the threadlinks $threadLinks = subStr($threadLinks, 0, -1); echo " $threadLinks | "; } // end if } // end function Helen

« previous php.general (#67191) next »