Re: [PHP-DB] LIMIT and get_num_rows

2002-01-14 Thread Jason Wong

On Monday 14 January 2002 19:21, Markus Lervik wrote:

> Damnit.
> Forgot to cc to the list, again. Here it is.
>
> --  Forwarded Message  --
>
> On Monday 14 January 2002 12:55, you wrote:
> > hi guys, just looking for verification on this, as i don't think there's
> > any way to do it
> >
> > Basically, i want to return the results for a search, but only return the
> > first 20 results from the start number given
> > LIMIT $start, 20
> > BUT... i'd like to have a page 1-whatever so if there are 65 results in
> > total, then the first 20 will be shown, but there will be options to move
> > to pages 2,3 or 4.
> > Obviously, if i use LIMIT, then it won't know that there are 65 in total,
> > so how would i get around this? do i just have to do the full query, and
> > then only use the first 20 results in the results set?
> > just becomes a bit of a problem if there are, say, 8000 results returned!
> > would it just be best to return the first 200 using LIMIT, and do my
> > pages for those, with a note that there are more than 200 results, and to
> > refine the search criteria?
> > Cheers,
> >   Matt
>
> Matt,
>
> Here's how I did the "20 results per page". Messy, I know, but
> it was the only way I figured out how to do it.
>
> $query="SELECT * FROM table";
>
> $result=mysql_query($query,$database);
> $nr=mysql_num_rows($result);
> /* Here you can slap in a check for how many results
> you want, ie:
>  */
> if($nr>200) {
> die("Bitch,whine and moan!");
> }
> $nr_pages=(ceil($nr/20));
>
> Or, you could, in the first SELECT statement put in a
> LIMIT 200, I suppose that would work, too.
> I'd have to dig into this myself too, as my database will
> have a tad over 100 000 records when it's done.
>
>
> Then I have two buttons, prev & next that's got a little
> javascript slapped on them;
>
>  onclick="parent.location='nav.php?nav=true&go=prev';">

One potential problem (or feature, depending on which way you look at it!)  
is that refreshing/reloading a page will jump to the next or previous page 
depending on which action was last performed.

The way around this is to pass a position variable indicating which page of 
results to view, rather than an 'action' variable.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
In real love you want the other person's good.  In romantic love you
want the other person.
-- Margaret Anderson
*/

-- 
PHP Database 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-DB] LIMIT and get_num_rows

2002-01-14 Thread Markus Lervik


Damnit.
Forgot to cc to the list, again. Here it is.

--  Forwarded Message  --

On Monday 14 January 2002 12:55, you wrote:
> hi guys, just looking for verification on this, as i don't think there's
> any way to do it
>
> Basically, i want to return the results for a search, but only return the
> first 20 results from the start number given
> LIMIT $start, 20
> BUT... i'd like to have a page 1-whatever so if there are 65 results in
> total, then the first 20 will be shown, but there will be options to move
> to pages 2,3 or 4.
> Obviously, if i use LIMIT, then it won't know that there are 65 in total,
> so how would i get around this? do i just have to do the full query, and
> then only use the first 20 results in the results set?
> just becomes a bit of a problem if there are, say, 8000 results returned!
> would it just be best to return the first 200 using LIMIT, and do my pages
> for those, with a note that there are more than 200 results, and to refine
> the search criteria?
> Cheers,
>   Matt

Matt,

Here's how I did the "20 results per page". Messy, I know, but
it was the only way I figured out how to do it.

$query="SELECT * FROM table";

$result=mysql_query($query,$database);
$nr=mysql_num_rows($result);
/* Here you can slap in a check for how many results
you want, ie:
 */
if($nr>200) {
die("Bitch,whine and moan!");
}
$nr_pages=(ceil($nr/20));

Or, you could, in the first SELECT statement put in a
LIMIT 200, I suppose that would work, too.
I'd have to dig into this myself too, as my database will
have a tad over 100 000 records when it's done.


Then I have two buttons, prev & next that's got a little
javascript slapped on them;



etc.

Then, in nav.php:

if($go=="next") {
if($page < $nr_pages && $page >= 0) {
 $page++;
 $with= (($page) * 20).",";
 $what = (($page-1) * 20).",";
 $query=ereg_replace($what,$with,$query);
}
}

if($go=="prev") {
if($page>=1 && $page <= $nr_pages) {
$page--;
$with = (($page) * 20).",";
$what  = (($page+1) * 20).",";
$query=ereg_replace($what,$with,$query);
}
}

$result=mysql_query($query,$database)
print_table(); //processes the query


If you got any questions regarding my code,
please do drop me a mail.


Cheers,
Markus



---

-- 
Markus Lervik
Linux-administrator with a kungfoo grip
Vaasa City Library - Regional Library
[EMAIL PROTECTED]
+358-6-325 3589 / +358-40-832 6709

-- 
PHP Database 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-DB] LIMIT and get_num_rows

2002-01-14 Thread Jason Wong

On Monday 14 January 2002 19:06, matt stewart wrote:
> but presumably if i'm doing a SELECT count(*) FROM Designs WHERE Keywords
> LIKE "%sport%"
> followed by a SELECT * FROM Designs WHERE Keywords LIKE "%sport%" LIMIT
> 0,20
>
> it's still using nearly as much processing time as just returning all the
> designs and just using a get_num_rows and then only using the first 20?
>


Possibly, I don't know. BUT if query returns 8000 records as opposed to 20, 
then it definitely uses up a bit more memory. This may be an issue if you 
have loads of such queries happening simultaneously.



-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Love is not enough, but it sure helps.
*/

-- 
PHP Database 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-DB] LIMIT and get_num_rows

2002-01-14 Thread matt stewart

but presumably if i'm doing a SELECT count(*) FROM Designs WHERE Keywords
LIKE "%sport%"
followed by a SELECT * FROM Designs WHERE Keywords LIKE "%sport%" LIMIT 0,20
 
it's still using nearly as much processing time as just returning all the
designs and just using a get_num_rows and then only using the first 20?

-Original Message-
From: Jonatan Bagge [mailto:[EMAIL PROTECTED]]
Sent: 14 January 2002 11:00
To: matt stewart
Subject: Re: [PHP-DB] LIMIT and get_num_rows


First do a SELECT count(*) from tablename; 
This will get the number of entries... 

The rest should be simple... 


matt stewart wrote: 


hi guys, just looking for verification on this, as i don't think there's any

way to do it 

Basically, i want to return the results for a search, but only return the 
first 20 results from the start number given 
LIMIT $start, 20 
BUT... i'd like to have a page 1-whatever so if there are 65 results in 
total, then the first 20 will be shown, but there will be options to move to

pages 2,3 or 4. 
Obviously, if i use LIMIT, then it won't know that there are 65 in total, so

how would i get around this? do i just have to do the full query, and then 
only use the first 20 results in the results set? 
just becomes a bit of a problem if there are, say, 8000 results returned! 
would it just be best to return the first 200 using LIMIT, and do my pages 
for those, with a note that there are more than 200 results, and to refine 
the search criteria? 
Cheers, 
  Matt 


--- 
Outgoing mail is certified Virus Free. 
Checked by AVG anti-virus system ( HYPERLINK
"http://www.grisoft.com"http://www.grisoft.com). 
Version: 6.0.313 / Virus Database: 174 - Release Date: 02/01/02 
  


-- 
PHP Database Mailing List ( HYPERLINK
"http://www.php.net/"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]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.313 / Virus Database: 174 - Release Date: 02/01/02



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.313 / Virus Database: 174 - Release Date: 02/01/02
 



[PHP-DB] LIMIT and get_num_rows

2002-01-14 Thread matt stewart

hi guys, just looking for verification on this, as i don't think there's any
way to do it

Basically, i want to return the results for a search, but only return the
first 20 results from the start number given
LIMIT $start, 20
BUT... i'd like to have a page 1-whatever so if there are 65 results in
total, then the first 20 will be shown, but there will be options to move to
pages 2,3 or 4.
Obviously, if i use LIMIT, then it won't know that there are 65 in total, so
how would i get around this? do i just have to do the full query, and then
only use the first 20 results in the results set?
just becomes a bit of a problem if there are, say, 8000 results returned!
would it just be best to return the first 200 using LIMIT, and do my pages
for those, with a note that there are more than 200 results, and to refine
the search criteria?
Cheers,
  Matt

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.313 / Virus Database: 174 - Release Date: 02/01/02
 

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