Re: Flipping through database records
| From: | Todd WIlliamsen | Date: | Wed, 13 Feb 2002 05:09:12 +0000 |
| Subject: | Re: Flipping through database records | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16887@lists.php.net to get a copy of this message | ||
how about just not do it by userid? query some other column thats in there
maybe by last name?
SELECT * FROM $tablename WHERE lname = $lname LIMIT [#results per page]
That should eliminate gaps
"Olinux" <olnx@yahoo.com> wrote in message
news:20020213043523.70699.qmail@web11805.mail.yahoo.com...
> Interesting Jason, just to make sure I'm clear:
>
> basically, you would query the table and
> while loop through the query result and create an
> array and then store that in a session?
>
> olinux
>
>
> --- Jason Cox <jason@darkpenguin.com> wrote:
> > Dan,
> >
> > Here's an idea for you:
> >
> > Rather than try to pass the uid through the pages,
> > pass a counter that will
> > act as an index to your result array. For example,
> > let's say you have a
> > query like: select * from myTable order by someCol;
> > The order by will help
> > give some sort of uniformity to the list on each
> > page. Each time you access
> > the page, you would run this query and stuff
> > everything into an array. The
> > index would be passed in and indicate which record
> > in the array to display.
> > You would know whether to display the 'prev' and
> > 'next' labels by comparing
> > the index to the size of the array.
> >
> > If your table is large than you can optimize your
> > query so you're not
> > returning all the rows everytime. If the index was
> > $idx then you could do
> > something like: select * from myTable order by
> > someCol limit $idx; So if
> > you had a hundred records and your index was 10 then
> > you would only get the
> > first 10 records. Since we're including the order
> > by clause, the 10 should
> > pretty much stay the same if the table doesn't
> > change very often. With this
> > technique you would need to do a count() to find out
> > the maximum number rows
> > in the table. Since a count() is faster than a
> > query returning many rows,
> > the combination of these two statements would be a
> > bit faster than running
> > the original query on a large table. But then
> > again, on a large table I
> > doubt someone would want to browse each row. That's
> > kinda like looking for
> > a good book by browsing the card catalog at the
> > library... :)
> >
> > Hope that helps,
> > Jason Cox
>
> __________________________________________________
> Do You Yahoo!?
> Send FREE Valentine eCards with Yahoo! Greetings!
> http://greetings.yahoo.com