You would pass the array index between pages.  For instance, let's say I had
the following db schema:

table: user
username varchar(10)
fname varchar(10)
lname varchar(10)
dob data(14)
...ect

Now let's say that there are 10 records in the table.  Each time I visit the
page I would do something like the following:

$query = "SELECT * FROM user ORDER BY username;";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
mysql_data_seek($result,$idx); //$idx is the Get var that is passed in
$row = mysql_fetch_array($result);
echo "username: ".$row["username"]." ect...";

if($idx > 0)
    echo "<a href=\"mypage.php?idx=".$idx-1."\">prev</a>";
if($idx < $num_rows-1)
 echo "<a href=\"mypage.php?idx=".$idx+1."\">next</a>";

That should give you the general idea.  The array that you get from mysql on
every page will be about the same.  Since we're doing an 'order by' atleast
the rows will be in the same order every time.  The only thing you'll have
to worry about is if someone adds rows while your browsing.  Even then the
only thing that might happen is that you browse on a record that you've
already seen because one was inserted either before or after the one you
were just looking at.

Hope that clears it up a bit.  To answer a previous quesiton for another
post, no you wouldn't store the array in the session.  That wouldn't be a
good idea unless you want to expose your data to the world.

--jason
----- Original Message -----
From: "Dan Swensen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 12, 2002 11:40 PM
Subject: Re: [PHP-DB] Flipping through database records


> 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" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> 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" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > 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 <[EMAIL PROTECTED]> 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
> >
> >
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to