in reply to next prev record mysql table

Try using the LIMIT feature of SELECT as in:
$stmt = "SELECT * FROM tablename LIMIT $place,1";
where $place is equal to what record you want. You will need to keep track of what record you are on by writing to a hidden input value in your html or writing a cookie. Of course, you have to do the maintenance of testing for if your are displaying the first record, or the last record and whether to show a Previous button or a Next button. I get the total number of records with:
$stmt = "SELECT COUNT(*) FROM tablename";
See my scratch pad for how I did this showing a list of book "reviews" with MySQL and HTML::Template.

—Brad
"A little yeast leavens the whole dough."

Replies are listed 'Best First'.
Re: Re: next prev record mysql table
by Anonymous Monk on Dec 07, 2003 at 02:04 UTC
    I really don't like this idea for one reason. Your data is going to move and shift, so your pages change and shift.

    It's probablybest that you keep track of the last element retrieved. For the first page:

    select * from table order by something limit 10

    and for next pages, do

    select * from table  where value > lastValueFromPriorQuery order by something limit 10

    It's a pain in the ass when people add data or delete it and your pages go a little nutty. Your idea is great if your data doesn't change.

      I see your point, however I seems that because I am only grabbing and displaying one record at a time, and keeping track of it, I shouldn't have any problems other than an unexpected record displaying when cycling back through previous records. But I'm open to refinement if any one has a safer/cleaner way of doing this.

      —Brad
      "A little yeast leavens the whole dough."