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;
>
> <INPUT TYPE=button VALUE="previous page"
> 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]

Reply via email to