Mysql: next and previous

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    Mysql: next and previous

    Does exist a next prev function in PHP/Mysql. I've a website with returns
    lot of records (say about 200). The user may browse trough the list or
    returned records, but he has to click the record result then click back's
    browser in order to see the next record. I'd like to provide a "see next"
    and "see previous" record in the details itself. How to do so ?

    Bob


  • Shakotah

    #2
    Re: Mysql: next and previous

    Bob Bedford wrote:[color=blue]
    > Does exist a next prev function in PHP/Mysql. I've a website with
    > returns lot of records (say about 200). The user may browse trough the
    > list or returned records, but he has to click the record result then
    > click back's browser in order to see the next record. I'd like to
    > provide a "see next" and "see previous" record in the details itself.
    > How to do so ?
    >
    > Bob
    >
    >[/color]
    Hi,

    Try out the pear(pear.php.n et) Pager package.

    Hope to have helped ;-)

    Comment

    • jerry gitomer

      #3
      Re: Mysql: next and previous

      Bob Bedford wrote:[color=blue]
      > Does exist a next prev function in PHP/Mysql. I've a website with
      > returns lot of records (say about 200). The user may browse trough the
      > list or returned records, but he has to click the record result then
      > click back's browser in order to see the next record. I'd like to
      > provide a "see next" and "see previous" record in the details itself.
      > How to do so ?
      >
      > Bob
      >
      >[/color]

      In a Relational Data Base Management System the data is stored
      at random and order is imparted by indices. As a result there
      is no valid previous or next in the database.

      If you want to use previous and next create an additional column
      in your table, use it to hold an auto-increment value, and index
      on the value. You will then have to write your own functions
      to retrieve the next and previous rows from your table.
      Assuming that you increment by one and that the table is fully
      populated you might use something that starts like:

      function get_next(id) {
      $get_id = $id + 1;
      SQL = "SELECT * FROM my_table
      WHERE table_id = '$get_id'";

      (the rest is left as an exercise for the reader)

      Comment

      • [-= Chris =-]

        #4
        Re: Mysql: next and previous

        On Tue, 2 Nov 2004 13:55:20 +0100, "Bob Bedford"
        <bedford1@YouKn owWhatToDoHereh otmail.com> wrote:
        [color=blue]
        >Does exist a next prev function in PHP/Mysql. I've a website with returns
        >lot of records (say about 200). The user may browse trough the list or
        >returned records, but he has to click the record result then click back's
        >browser in order to see the next record. I'd like to provide a "see next"
        >and "see previous" record in the details itself. How to do so ?
        >
        >Bob
        >[/color]


        You can specify the number of records retured and the offset in the
        MySQL query. So, for instance, if you wanted ten records at a time you
        could do something like:


        SELECT * FROM table WHERE condition ORDER BY field LIMIT 10,$x

        where $x is the offset, then make the back/next links increment or
        decrement the value of $x

        BTW, I can never remember off the top of my head which order the LIMIT
        clause goes in, so it might be as above, or it might be LIMIT $x,10

        hth

        C

        Comment

        • Colin McKinnon

          #5
          Re: Mysql: next and previous

          Bob Bedford wrote:
          [color=blue]
          > Does exist a next prev function in PHP/Mysql. I've a website with returns
          > lot of records (say about 200). The user may browse trough the list or
          > returned records, but he has to click the record result then click back's
          > browser in order to see the next record. I'd like to provide a "see next"
          > and "see previous" record in the details itself. How to do so ?
          >
          > Bob[/color]

          You'll need a unique sort combination followed by the LIMIT keyword.

          HTH

          C.

          Comment

          • Tony Marston

            #6
            Re: Mysql: next and previous

            Take a look at http://www.tonymarston.co.uk/php-mysql/pagination.html

            --
            Tony Marston

            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



            "Bob Bedford" <bedford1@YouKn owWhatToDoHereh otmail.com> wrote in message
            news:418783b2$0 $28028$5402220f @news.sunrise.c h...[color=blue]
            > Does exist a next prev function in PHP/Mysql. I've a website with returns
            > lot of records (say about 200). The user may browse trough the list or
            > returned records, but he has to click the record result then click back's
            > browser in order to see the next record. I'd like to provide a "see next"
            > and "see previous" record in the details itself. How to do so ?
            >
            > Bob
            >
            >[/color]


            Comment

            Working...