#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    14
    Rep Power
    0
    i have some ideas to make a previous and next
    buttons from a query but I can't get them to work.

    I have:

    $id = 75

    SELECT id,name,cat FROM $table WHERE cat=$cat

    result=

    12 namex dog
    67 namea dog
    56 nameb dog
    75 namef dog
    77 namet dog
    99 namer dog

    Can I filter the previous and next id in the result from
    my $id???

    so you get:

    56 nameb dog
    75 namef dog
    77 namet dog

    If not, how can I make these 2 loops:

    A)
    $id++
    result = nothing (id=76)
    $id++
    result = 77 namet dog
    stop

    b)
    $id--
    result = nothing (id=74)
    $id--
    result = nothing (id=73)
    $id--
    result = nothing (id=72)

    ---
    $id--
    result = nothing (id=57)
    $id--
    result = 56 nameb dog
    stop


    Thanx allot
    Martijn
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    3
    Rep Power
    0
    Beste Martijn,

    there is perhaps a different solution, I'm not sure you like it.
    But is not difficult to find the next/prev id using a new query.

    For example, if you want to find the previous id, simply execute following query:

    SELECT max(id) FROM $table WHERE (id<$id)
    The result is 67 ($id=75 as in your example), and is the id of the previous record.

    For the next id, the query is:
    SELECT min(id) FROM $table WHERE (id>$id)

    With regards,

    Roald

IMN logo majestic logo threadwatch logo seochat tools logo