RE: [PHP] limiting rows and pages like google

2001-09-16 Thread Lawrence . Sheed

How about limiting results?

eg
limit the return page value after a certain number (say 10) to every 5
pages, then 50 pages a la google.



Page
1 2 3 4 5 6 7 8 9 10 ..15  ..20 ..50 ..100

This can be done relatively easily 

eg (untested)


for ($count=1;$count=$pages;$count++) {  // loop thru 
 //set modifier for page display
 if ($count  10)$iMod = 1;
elseif ($count 50)  $iMod = 5;
else $iMod=50;

 if ($count % $iMod==0) //Are we on an exact iMod boundary?
 print  a href=\$PHP_SELF?offset=$count\$i/a nbsp; \n;
 }


-Original Message-
From: Adrian D'Costa [mailto:[EMAIL PROTECTED]]
Sent: September 14, 2001 5:57 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; php general list
Subject: RE: [PHP] limiting rows and pages like google


Hi,

Thanks.  Instead of using next and previous I am giving the page number at
the bottom of the page (see lastminute.vvmm.net/nextweek.php).  The
problem is that if there are, say 35 pages, the page numbers go off the
screen.  This is the snippet:

  if ($nopage=$limit)
{

echo (centertable border=\0\ width=\100%\
tr
tdfont face=\Arial\ size=\1\Pagina/td);
for($j=1; $j=($nopage); $j++)
{
//$next = $limit*($j-1);
$xi = ($j-1);
echo(tdfont
face=\Arial\ size=\1\a
href=\$PHP_SELF?npage=$xi\[$page[$j]]/a/font
/td);

}
echo(  /tr
  /table/center);
}

Adrian

On Thu, 13 Sep 2001 [EMAIL PROTECTED] wrote:

 2 queries is ok imho, but let the database do all the work ;)
 
 The first query should be a select count (*) QUERY for a count.
 The second query should be the actual QUERY.
 
 Eg something cut 'n' pasted from some code of mine (not nice, but hey ;) )
 
 --
 
 $db = mysql_connect($db_domain, $db_user,$db_password);
 mysql_select_db($db_databasename,$db);
 
 $sqlwhere =  where CuisineID = $CuisineID ;
 
 $numresults=mysql_query( select count(*) from restaurants . $sqlwhere);
 $numrows=mysql_num_rows($numresults);
 
 // get results 
 $sqlstring= select ID, Name,LanguageID from restaurants . $sqlwhere .
 limit $offset,$limit;
 $result=@mysql_query($sqlstring,$db);
 
 //Do stuff with $result...
 
 // 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++;
 }
 
 for ($i=1;$i=$pages;$i++) {  // loop thru 
 $newoffset=$limit*($i-1);
 print  a href=\$PHP_SELF?offset=$newoffset\$i/a nbsp; \n;
 }
 
 // check to see if last page 
 if (!(($offset/$limit)==$pages)  $pages!=1) {
  // not last page so give NEXT link 
 $newoffset=$offset+$limit;
 print  a href=\$PHP_SELF?offset=$newoffset\NEXT/ap\n;
 }
 
 -Original Message-
 From: Julian Wood [mailto:[EMAIL PROTECTED]]
 Sent: September 14, 2001 1:34 AM
 To: php general list
 Subject: Re: [PHP] limiting rows and pages like google
 
 
 
 It's not too hard to do the next/previous through all your results, as 
 has been shown by several people. What is a little trickier, at least 
 when using mysql and trying to take advantage of the limit clause, is 
 how to display how many results you have (ie 1 to 10 of 107 results). If 
 you use the limit, you can't get the total number of rows, without doing 
 a second search sans limit. It's also harder to do the next link, 
 because you don't necessarily know if there are any more rows (imagine 
 you are displaying 10 rows at a time, you are on page 3 and there are 30 
 total rows). Conversely, if you do a single query without the limit, 
 then you're doing a slower search (limiting a search is way faster), and 
 I'm not sure of the implications of the full result set residing 
 serverside - maybe higher memory requirements. So what do people do to 
 take advantage of limit? Two queries or a single query? Any other 
 solutions? Any more insights on how limit works?
 
 Julian
 
 On Wednesday, September 12, 2001, at 10:16 PM, 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

RE: [PHP] limiting rows and pages like google

2001-09-14 Thread Adrian D'Costa

Hi,

Thanks.  Instead of using next and previous I am giving the page number at
the bottom of the page (see lastminute.vvmm.net/nextweek.php).  The
problem is that if there are, say 35 pages, the page numbers go off the
screen.  This is the snippet:

  if ($nopage=$limit)
{

echo (centertable border=\0\ width=\100%\
tr
tdfont face=\Arial\ size=\1\Pagina/td);
for($j=1; $j=($nopage); $j++)
{
//$next = $limit*($j-1);
$xi = ($j-1);
echo(tdfont
face=\Arial\ size=\1\a
href=\$PHP_SELF?npage=$xi\[$page[$j]]/a/font
/td);

}
echo(  /tr
  /table/center);
}

Adrian

On Thu, 13 Sep 2001 [EMAIL PROTECTED] wrote:

 2 queries is ok imho, but let the database do all the work ;)
 
 The first query should be a select count (*) QUERY for a count.
 The second query should be the actual QUERY.
 
 Eg something cut 'n' pasted from some code of mine (not nice, but hey ;) )
 
 --
 
 $db = mysql_connect($db_domain, $db_user,$db_password);
 mysql_select_db($db_databasename,$db);
 
 $sqlwhere =  where CuisineID = $CuisineID ;
 
 $numresults=mysql_query( select count(*) from restaurants . $sqlwhere);
 $numrows=mysql_num_rows($numresults);
 
 // get results 
 $sqlstring= select ID, Name,LanguageID from restaurants . $sqlwhere .
 limit $offset,$limit;
 $result=@mysql_query($sqlstring,$db);
 
 //Do stuff with $result...
 
 // 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++;
 }
 
 for ($i=1;$i=$pages;$i++) {  // loop thru 
 $newoffset=$limit*($i-1);
 print  a href=\$PHP_SELF?offset=$newoffset\$i/a nbsp; \n;
 }
 
 // check to see if last page 
 if (!(($offset/$limit)==$pages)  $pages!=1) {
  // not last page so give NEXT link 
 $newoffset=$offset+$limit;
 print  a href=\$PHP_SELF?offset=$newoffset\NEXT/ap\n;
 }
 
 -Original Message-
 From: Julian Wood [mailto:[EMAIL PROTECTED]]
 Sent: September 14, 2001 1:34 AM
 To: php general list
 Subject: Re: [PHP] limiting rows and pages like google
 
 
 
 It's not too hard to do the next/previous through all your results, as 
 has been shown by several people. What is a little trickier, at least 
 when using mysql and trying to take advantage of the limit clause, is 
 how to display how many results you have (ie 1 to 10 of 107 results). If 
 you use the limit, you can't get the total number of rows, without doing 
 a second search sans limit. It's also harder to do the next link, 
 because you don't necessarily know if there are any more rows (imagine 
 you are displaying 10 rows at a time, you are on page 3 and there are 30 
 total rows). Conversely, if you do a single query without the limit, 
 then you're doing a slower search (limiting a search is way faster), and 
 I'm not sure of the implications of the full result set residing 
 serverside - maybe higher memory requirements. So what do people do to 
 take advantage of limit? Two queries or a single query? Any other 
 solutions? Any more insights on how limit works?
 
 Julian
 
 On Wednesday, September 12, 2001, at 10:16 PM, 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
 
 
  --
  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]
 
 
 --
 Julian Wood
 
 Programmer/Analyst
 University of Calgary
 
 


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

2001-09-13 Thread Julian Wood


It's not too hard to do the next/previous through all your results, as 
has been shown by several people. What is a little trickier, at least 
when using mysql and trying to take advantage of the limit clause, is 
how to display how many results you have (ie 1 to 10 of 107 results). If 
you use the limit, you can't get the total number of rows, without doing 
a second search sans limit. It's also harder to do the next link, 
because you don't necessarily know if there are any more rows (imagine 
you are displaying 10 rows at a time, you are on page 3 and there are 30 
total rows). Conversely, if you do a single query without the limit, 
then you're doing a slower search (limiting a search is way faster), and 
I'm not sure of the implications of the full result set residing 
serverside - maybe higher memory requirements. So what do people do to 
take advantage of limit? Two queries or a single query? Any other 
solutions? Any more insights on how limit works?

Julian

On Wednesday, September 12, 2001, at 10:16 PM, 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


 --
 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]


--
Julian Wood

Programmer/Analyst
University of Calgary

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

2001-09-13 Thread Lawrence . Sheed

2 queries is ok imho, but let the database do all the work ;)

The first query should be a select count (*) QUERY for a count.
The second query should be the actual QUERY.

Eg something cut 'n' pasted from some code of mine (not nice, but hey ;) )

--

$db = mysql_connect($db_domain, $db_user,$db_password);
mysql_select_db($db_databasename,$db);

$sqlwhere =  where CuisineID = $CuisineID ;

$numresults=mysql_query( select count(*) from restaurants . $sqlwhere);
$numrows=mysql_num_rows($numresults);

// get results 
$sqlstring= select ID, Name,LanguageID from restaurants . $sqlwhere .
limit $offset,$limit;
$result=@mysql_query($sqlstring,$db);

//Do stuff with $result...

// 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++;
}

for ($i=1;$i=$pages;$i++) {  // loop thru 
$newoffset=$limit*($i-1);
print  a href=\$PHP_SELF?offset=$newoffset\$i/a nbsp; \n;
}

// check to see if last page 
if (!(($offset/$limit)==$pages)  $pages!=1) {
 // not last page so give NEXT link 
$newoffset=$offset+$limit;
print  a href=\$PHP_SELF?offset=$newoffset\NEXT/ap\n;
}

-Original Message-
From: Julian Wood [mailto:[EMAIL PROTECTED]]
Sent: September 14, 2001 1:34 AM
To: php general list
Subject: Re: [PHP] limiting rows and pages like google



It's not too hard to do the next/previous through all your results, as 
has been shown by several people. What is a little trickier, at least 
when using mysql and trying to take advantage of the limit clause, is 
how to display how many results you have (ie 1 to 10 of 107 results). If 
you use the limit, you can't get the total number of rows, without doing 
a second search sans limit. It's also harder to do the next link, 
because you don't necessarily know if there are any more rows (imagine 
you are displaying 10 rows at a time, you are on page 3 and there are 30 
total rows). Conversely, if you do a single query without the limit, 
then you're doing a slower search (limiting a search is way faster), and 
I'm not sure of the implications of the full result set residing 
serverside - maybe higher memory requirements. So what do people do to 
take advantage of limit? Two queries or a single query? Any other 
solutions? Any more insights on how limit works?

Julian

On Wednesday, September 12, 2001, at 10:16 PM, 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


 --
 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]


--
Julian Wood

Programmer/Analyst
University of Calgary

-- 
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]

-- 
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]




[PHP] limiting rows and pages like google

2001-09-12 Thread Adrian D'Costa

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


-- 
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]




[PHP] limiting rows and pages like google

2001-09-12 Thread Aniceto Lopez

paging results:

this is tha idea
page 1 - SELECT * FROM yourtable ORDER BY id DESC LIMIT 0, 20
page 2 - SELECT * FROM yourtable ORDER BY id DESC LIMIT 21, 20
page 3 - SELECT * FROM yourtable ORDER BY id DESC LIMIT 41, 20
...
so
$next = 0 //starting
SELECT * FROM yourtable ORDER BY id DESC LIMIT $next, 20
$next = $next + 20 //next pages
till $next  max(id)

is this helping you?

Ani Lopez
www.lamundial.net
download and spread our music 


-- 
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]




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

2001-09-12 Thread Adrian D'Costa

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



-- 
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]