Re: Flipping through database records
| From: | Dan Swensen | Date: | Wed, 13 Feb 2002 06:40:28 +0000 |
| Subject: | Re: Flipping through database records | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16889@lists.php.net to get a copy of this message | ||
Actually, now that I think of it... how would you move from one record to
the next, if not querying by userid?
Optimally, I would like to have a page that displays one row from a table,
and links that will allow a user to go to the next or previous row via
hyperlink. At first glance I can't think how you would do that querying by,
say, lname or the like.
----- Original Message -----
From: "Todd WIlliamsen" <todd@williamsen.net>
To: <php-db@lists.php.net>
Sent: Tuesday, February 12, 2002 10:09 PM
Subject: Re: [PHP-DB] Flipping through database records
> 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
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>