Connecting Tech Pros Worldwide Forums | Help | Site Map

Mysql: next and previous

Bob Bedford
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Guest
 
Posts: n/a
#2: Jul 17 '05

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.net) Pager package.

Hope to have helped ;-)
jerry gitomer
Guest
 
Posts: n/a
#3: Jul 17 '05

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)
[-= Chris =-]
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Mysql: next and previous


On Tue, 2 Nov 2004 13:55:20 +0100, "Bob Bedford"
<bedford1@YouKnowWhatToDoHerehotmail.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

Colin McKinnon
Guest
 
Posts: n/a
#5: Jul 17 '05

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.
Tony Marston
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Mysql: next and previous


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

--
Tony Marston

http://www.tonymarston.net


"Bob Bedford" <bedford1@YouKnowWhatToDoHerehotmail.com> wrote in message
news:418783b2$0$28028$5402220f@news.sunrise.ch...[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]


Closed Thread