Re: [PHP] limiting rows and pages like google -- again

2001-09-13 Thread Adrian D'Costa

On Thu, 13 Sep 2001, Helen wrote:

  The logic would be to check if the script is called the first time, then
  the sql statement would be select travel.*, city.city from travel, city
  where travel.cityid=city.id limit 0,20.
  The second time or based on what has been selected on the page (1-20,
  21-40, etc) add that to the sql statement.  My question is how
 
 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.

Thanks

Adrian


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] limiting rows and pages like google -- again

2001-09-13 Thread Helen

  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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] limiting rows and pages like google -- again

2001-09-12 Thread David Robley

On Thu, 13 Sep 2001 14:55, Adrian D'Costa wrote:
 Hi,

 I am trying to find out the the best way to do the following:

 I have a script that select records from a table.  The problem is that
 I need to limit the rows to 20. I know that I can use limit 20.  But
 what I want to do is give the view a link to the next 20 till all the
 records are shown.  What I don't know is how to maintain the search
 query and I want to use the same script.

 The logic would be to check if the script is called the first time,
 then the sql statement would be select travel.*, city.city from travel,
 city where travel.cityid=city.id limit 0,20.
 The second time or based on what has been selected on the page (1-20,
 21-40, etc) add that to the sql statement.  My question is how?

 Can someone guide me or give me some example.

 TIA

 Adrian

This has been a common topic recently. Try the archives

http://marc.theaimsgroup.com/?l=php-generalr=1w=2q=bs=pages+like+google

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Useless Invention: Flashbulb tester.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]